1

我已经设置了我的重力,所以在我的游戏开始时,物体下落的速度很慢,当玩家收集这些物品时,我希望重力增加。

override func didMove(to view: SKView) {
    self.physicsWorld.gravity = CGVector(dx: 0.0, dy: -3.0)
    initializeGame()
}

我已经像这样设置了重力,但我不确定如何使用 if 语句对其进行编辑。例如,如果分数 = 20,重力会增加。对于如何正确执行此操作,任何帮助都会非常有用

4

2 回答 2

0

您可能想查看 SpriteKit 教程。通常,更新属性发生在update(_ currentTime: TimeInterval)方法中。您可以在您的 SKScene 子类中实现此方法:

override func update(_ currentTime: TimeInterval) {
    if (score == 20) { // whatever condition you want
        // whatever you want to do
    }
}
于 2017-08-15T05:23:07.977 回答
0
if (score == 20) { 
self.physicsWorld.gravity = CGVector(dx: 0.0, dy: -8.0)
}
Change value of 'dy' as per your requirements
于 2017-08-16T17:51:17.567 回答