SKPhysicsBody with restitution 0 still bounces

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 17:35:25

问题


I'm am trying to drop the SKSpriteNode with constant speed and without bouncing.

Here is the code I'm using:

SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)];
floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size];
floor.physicsBody.restitution = 0.0f;
floor.physicsBody.dynamic = NO;
floor.physicsBody.allowsRotation = NO;

SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:imageName]];
block.position = CGPointMake(160, 300);
block.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(block.size.width - 2, block.size.height)];
block.physicsBody.dynamic = dynamic;
block.physicsBody.restitution = 0.0f;
block.physicsBody.allowsRotation = NO;

When I vary the restitution value, I can see the difference in block bouncing, but when it's zero it still bounces a little bit. When multiple blocks are stacked, the below blocks also bounce a little bit.

How can I totally disable bouncing?


回答1:


After some trial and error I've discovered that the Physics Engine is not meant to be used if you want accurate positioning of your elements. That's why in my board game, I have re-implemented the code in order to make posit



来源:https://stackoverflow.com/questions/24315250/skphysicsbody-with-restitution-0-still-bounces

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