swift 2 : Stop movement after applyImpulse

标签 swift sprite-kit

我怎样才能在 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/

相关文章:

ios - 如何通过命令行对 Swift 应用程序进行代码设计?

swift - 如何从 SKNode.children 数组访问 SKNode 子类方法?

iOS/swift : moving between view controllers in swift

ios - 所有 Storyboard、xib 文件都不会在 Macbook Pro M1 上使用 rosetta 更新框架或约束(遇到与 IBAgent-iOS 通信的错误)

Swift - 加载横幅时更改应用程序。 - Xcode 6 通用汽车

ios - SKAction.repeatActionForever 只在第一次调用时计算随机数

sprite-kit - Sprite Kit 中的计时器

ios - TouchBegan/TouchEnded 数组

ios - 在 sprite kit 中使用渐变效果将 fps 从 60 降低到 30

swift - Swift 和 SpriteKit 如何将用户的分数转移到另一个场景?