Swift 2:在applyImpulse之后停止运动

前端之家收集整理的这篇文章主要介绍了Swift 2:在applyImpulse之后停止运动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在应用了这样的冲动后停止精灵:

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

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

解决方法

为了阻止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

猜你在找的Swift相关文章