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

后端 未结 2 1435
栀梦
栀梦 2021-01-14 18:10

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 correc

相关标签:
2条回答
  • 2021-01-14 18:49

    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.

    0 讨论(0)
  • 2021-01-14 19:08

    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

    0 讨论(0)
提交回复
热议问题