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

做~自己de王妃 提交于 2019-12-21 20:06:07

问题


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....


回答1:


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




回答2:


quick and easy way without math: 1 use flash to tween your box warping. 2 export the tweened frames as a sprite sheet (texture atlas) 3 animate the texture atlas on contact with an edge physics body in your scene.

your box will fall and on contact animate the separate images to give the impression its warping/bulging sides.

i used this method and it works - in other words it gives the desired effect, which in my view is what is important - your gamers don't care how you did it, as long as it looks great.



来源:https://stackoverflow.com/questions/22381546/is-there-a-way-to-make-a-soft-body-with-spritekit-using-skspritenode-and-physics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!