Does SpriteKit apply physics if I modify the position and rotation of a SKSpriteNode directly without an SKAction?

痴心易碎 提交于 2019-12-19 09:23:27

问题


For example if I want to do my own custom animation and move an SKSpriteNode every frame programmatically by x += 10, will Sprite Kit still apply physics correctly or must I always use SKAction?


回答1:


Manually moving a node with a physics body is possible regardless of how or when you do it. But in any case it's not recommended since it can adversely affect the physics simulation. The node (view) could be out of sync with the position of the body for 1 frame, and you might move the body into a collision which the physics engine will forcibly resolve, causing jumps, jitter, exploding velocities or skipping collisions.

When you use physics, stick to moving the physics body through force, impulse or changing the body velocity directly.




回答2:


No, you don't have to use SKAction to move SKSpriteNode. This approach works fine for me:

- (void)update:(CFTimeInterval)currentTime {
     myNode.position = CGPointMake(myNode.position.x + 0.1,myNode.position.y);
}

All physics work as expected



来源:https://stackoverflow.com/questions/20719413/does-spritekit-apply-physics-if-i-modify-the-position-and-rotation-of-a-sksprite

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