Search code examples
sprite-kitskspritenodeskphysicsbodysoftbody

Is there a way to make a soft body with Spritekit using SKSpriteNode and PhysicsBody parameters?


I have the following sprite that falls to the bottom of the screen:

// The View
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsWorld.contactDelegate = self;

// The Sprite
SKSpriteNode *cube = [[SKSpriteNode alloc] initWithImageNamed:@"cube"];
[cube setPosition:CGPointMake(160,250);
[self addChild:cube];

// The Physics
cube.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:cube.frame.size];
cube.physicsBody.dynamic = YES;
cube.physicsBody.affectedByGravity = YES;
cube.physicsBody.mass = 0.02;

Is there a way to make it so its sides are bulging when it hits the bottom border of the screen? Something that would be Jelly like or a soft body that still maintains its shape to some extent but bulges out under its own weight? I hope this makes sense....


Solution

  • Visit the site https://gist.github.com/kazukitanaka0611/4b9d4ac9dff0cd317b6c it have explanation and source code for soft bodies (jelly) in sprite kit