Swift 2:在applyImpulse之后停止运动

时间:2016-03-12 15:04:29

标签: swift sprite-kit

如何在应用了这样的冲动后停止精灵:

player.physicsBody!.applyImpulse(CGVectorMake(50, 0))

是否有可能使运动在一段时间内减少? (2秒)

1 个答案:

答案 0 :(得分:7)

为了阻止physicsBody的移动,您可以像这样使用'velocity'变量:

//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'来影响速度,'angularDamping'来影响angularVelocity(旋转)。这些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