有什么方法可以在Swift中逐步加快游戏玩法?

Jak*_*ake 3 nstimer ios sprite-kit swift

我目前正在使用Spritekit开发游戏.游戏具有在屏幕顶部产生并落向玩家角色的物体,并且当玩家角色与任何物体碰撞时游戏结束.我试图找到一种随着时间的推移逐渐加快游戏速度以使游戏更加困难的方法(即当游戏开始时物体以正常速度下降,5秒后加速50%,再过5秒后再加速50%,无限的.)

Would I need to use NSTimer to make a countdown to increase the gravity applied to the falling objects? Sorry if this is a basic thing, I'm kind of new to programming.

Thanks, Jake

EDIT:

My spawn method for enemies-

let spawn = SKAction.runBlock({() in self.spawnEnemy()})
let delay = SKAction.waitForDuration(NSTimeInterval(2.0))
let spawnThenDelay = SKAction.sequence([spawn, delay])
let spawnThenDelayForever = SKAction.repeatActionForever(spawnThenDelay)
self.runAction(spawnThenDelayForever)
Run Code Online (Sandbox Code Playgroud)

And my method for making the enemies fall-

func spawnEnemy() {
    let enemy = SKNode()
    let x = arc4random()
    fallSprite.physicsBody = SKPhysicsBody(rectangleOfSize: fallSprite.size)
    fallSprite.physicsBody.dynamic = true
    self.physicsWorld.gravity = CGVectorMake(0.0, -0.50)
    enemy.addChild(fallSprite)
}
Run Code Online (Sandbox Code Playgroud)

erd*_*ser 6

spawnEnemy(),你设置self.physicsWorld.gravity.将此行移动到您的update:方法.

如果你现在没有跟踪游戏的持续时间,你将需要实现它.您可以使用update:方法的参数来完成此操作.

然后,您可以使用游戏持续时间来改变重力.

例如,

override func update(currentTime: CFTimeInterval) {
    if gameState == Playing{
        //update "duration" using "currentTime"
        self.physicsWorld.physicsBody = CGVectorMake(0.0, -0.50 * (duration / 10.0))
    }
}
Run Code Online (Sandbox Code Playgroud)

10.0可以根据您希望重力增加的速度来改变.数字越大,变化越小,数字越小,重力越快.

希望这能回答你的问题.