恢复原状的SKPhysicsBody仍然弹跳 [英] SKPhysicsBody with restitution 0 still bounces

查看:134
本文介绍了恢复原状的SKPhysicsBody仍然弹跳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以恒定速度且不发生反弹的方式丢弃SKSpriteNode。

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?

推荐答案

错误我发现,如果要精确定位元素,则不建议使用物理引擎。这就是为什么在我的棋盘游戏中,我重新实现了代码以进行定位

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

这篇关于恢复原状的SKPhysicsBody仍然弹跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆