如果我在没有SKAction的情况下直接修改SKSpriteNode的位置和旋转,SpriteKit是否会应用物理?

时间:2021-06-10 23:11:18

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?

例如,如果我想做自己的自定义动画并以x + = 10编程方式每帧移动一个SKSpriteNode,Sprite Kit是否仍然正确应用物理或者我是否必须始终使用SKAction?

2 个解决方案

#1


4  

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.

无论您何时或何时进行,都可以使用物理机构手动移动节点。但无论如何不推荐它,因为它会对物理模拟产生不利影响。节点(视图)可能与身体的位置不同步1帧,并且您可能将身体移动到物理引擎将强制解决的碰撞中,从而导致跳跃,抖动,爆炸速度或跳过碰撞。

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

当你使用物理学时,坚持通过力,冲动或直接改变体速来移动物理体。

#2


2  

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

不,您不必使用SKAction来移动SKSpriteNode。这种方法对我来说很好:

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

All physics work as expected

所有物理都按预期工作

#1


4  

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.

无论您何时或何时进行,都可以使用物理机构手动移动节点。但无论如何不推荐它,因为它会对物理模拟产生不利影响。节点(视图)可能与身体的位置不同步1帧,并且您可能将身体移动到物理引擎将强制解决的碰撞中,从而导致跳跃,抖动,爆炸速度或跳过碰撞。

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

当你使用物理学时,坚持通过力,冲动或直接改变体速来移动物理体。

#2


2  

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

不,您不必使用SKAction来移动SKSpriteNode。这种方法对我来说很好:

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

All physics work as expected

所有物理都按预期工作