我有一个使用 spritekit 物理世界的动画。我一直在寻找是否有一种方法可以通过物理“快进”并且只获得结果或路径而不显示动画。我看了 physicsWorld 并没有看到任何关于这个的东西?关于如何做到这一点的任何想法?
基本上,我想在用户决定执行之前向用户展示动画的结果位置。
最佳答案
显然您错过了 SKPhysicsWorld 中的 speed
属性:
The default value is 1.0, which means the simulation runs at normal speed. A value other than the default changes the rate at which time passes in the physics simulation. For example, a speed value of 2.0 indicates that time in the physics simulation passes twice as fast as the scene’s simulation time. A value of 0.0 pauses the physics simulation.
请记住,这会影响所有 body ,并且没有内置方法可以将系统重置为之前的状态。此外,模拟必须至少前进 1 步才能使更改变得可见,因此您必须在 update
或 didEvaluateActions 中将速度属性设置为 30
方法并在 didSimulatePhysics
中将其重置回 1。这也是您检查快进步骤结果的方法。
如果 body 以固定速度行进并且不会受到碰撞或重力等任何影响,您可以使用纯三角学(并且不需要速度属性)来找到 body 在 n 步中的位置,或 body 走至少 n 距离需要多少步。
在物体到达某个目的地之前,我想不出一种前进的方法,在该目的地,物体不会以固定速度行进,并且如果不实际运行物理模拟,您就没有简单的方法来预测到达时间。这将需要能够独立于场景的其余部分推进世界(并通过超时保护 body 永远不会真正到达那里),这只有第 3 方物理引擎才有可能。不过,您仍然可以将 Box2D 或 Chipmunk 与 Sprite Kit 一起使用。
关于ios - 加速 Sprite 套件的物理时钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20892214/