SpriteKit - 检测精灵是否静止 moving/stopped

SpriteKit - Detect if sprite still moving/stopped

我想检测我移动的精灵(施加脉冲后)是否停止了。 是否有类似 event/function 的东西可以处理这个问题?

谢谢

您可以检查物理体速度 向量以查看节点是否在任何方向上移动。有了这样的东西,你可能会没事的:

if((yournode.physicsBody.velocity.dx == 0.0f) && (yournode.physicsBody.velocity.dy == 0.0f)) {
   //do your stuff
}

在节点的物理体上还有一个叫做resting的属性,表示物体在物理模拟中是否处于静止状态。所以你可能会这样做:

if(yourNode.physicsBody.resting ) {
 //do your stuff
 }

您可以阅读有关休息属性in this SO answer的某些行为和建议。

希望对您有所帮助