Swift-Timer.scheduledTimer.timeInterval问题-增加节点繁殖率

Swift-Timer.scheduledTimer.timeInterval问题-增加节点繁殖率,swift,timer,Swift,Timer,我正在制作一个简单的SpriteKit游戏,其中物品掉落,我需要根据当前分数管理物品繁殖速度。但是我对Timer.scheduledTimer有一个问题 func manageItemsSpawnSpeed() { if score < 10 { itemsSpawnTimeInterval = 1.0 } else if score >= 10 && score < 20 { itemsSpawnTimeInte

我正在制作一个简单的SpriteKit游戏,其中物品掉落,我需要根据当前分数管理物品繁殖速度。但是我对Timer.scheduledTimer有一个问题

func manageItemsSpawnSpeed() {
    if score < 10 {
        itemsSpawnTimeInterval = 1.0
    } else if score >= 10 && score < 20 {
        itemsSpawnTimeInterval = 0.9
    } else if score >= 20 && score < 50 {
        itemsSpawnTimeInterval = 0.8
    } else if score >= 50 && score < 100 {
      itemsSpawnTimeInterval = 0.7
    }...
这里是物品产卵计时器,目前我只在游戏开始时调用它

func theSpawntimer() {
    Timer.scheduledTimer(timeInterval: TimeInterval(itemsSpawnTimeInterval), target: self, selector: #selector(GameplayScene.spawnItems), userInfo: nil, repeats: true)
}
所以,当分数发生变化时——itemsSpawnTimeInterval会很好地更新,但每次我再次调用Spawntimer()时,它也会启动额外的spawnItems(),而不是提高生成速度——它会使游戏中的项目下雨

请告知我如何在每次ItemsPawnTimeInterval更改时调用PawnItem(),而不调用spawnItems()。
有可能吗?

为了解决这个问题,我拒绝使用scheduledTimer。相反,我使用了SKAction:

func theSpawner() {
    removeAction(forKey: spawnKey) // remove previous action if running.
    let spawnAction = SKAction.run(spawnItems)
    let spawnDelay = SKAction.wait(forDuration: itemsSpawnTimeInterval)
    let spawnSequence = SKAction.sequence([spawnAction, spawnDelay])
    run(SKAction.repeatForever(spawnSequence), withKey: spawnKey) // run action with key so you can cancel it later
func theSpawner() {
    removeAction(forKey: spawnKey) // remove previous action if running.
    let spawnAction = SKAction.run(spawnItems)
    let spawnDelay = SKAction.wait(forDuration: itemsSpawnTimeInterval)
    let spawnSequence = SKAction.sequence([spawnAction, spawnDelay])
    run(SKAction.repeatForever(spawnSequence), withKey: spawnKey) // run action with key so you can cancel it later