我怎样才能在 Sprite 被施加这样的冲动后停止它:
player.physicsBody!.applyImpulse(CGVectorMake(50, 0))
是否有可能使运动在一段时间内减少? (2 秒)
最佳答案
为了停止 physicsBody 的运动,您可以像这样使用“速度”变量:
//this will reset the x, y based velocity to a halt/stop
player.physicsBody?.velocity = CGVectorMake(0, 0)
//if you would also like to stop any rotation that may be present
player.physicsBody?.angularVelocity = 0
要解决您的第二个问题,您应该查看影响速度的“linearDamping”和影响 angularVelocity(旋转)的“angularDamping”。这些 physicsBody 参数允许您在施加脉冲(类似于摩擦)后随时间减慢速度。
//These values should be set when creating the physicsBody.
//should experiment with these values to get the desired effect.
player.physicsBody?.linearDamping = 1.10
player.physicsBody?.angularDamping = 0.25
关于 swift 2 : Stop movement after applyImpulse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35959287/