我正在尝试增加一个变量,我将其作为NSTimeInterval加时使用,得分上升20点
这是我目前的代码
/* Create and Spawn enemy birds */
func enemySpawn() {
enemyBirdPhysics()
// ENEMY BIRD ONE
// Random Height
let maxHeight:UInt32 = UInt32(self.frame.size.height - enemyBird.size.height)
let moveToEndAction = SKAction.moveToX(0 - enemyBird.size.width, duration: 1.5)
let resetTostartAction = SKAction.runBlock { () -> Void in
var randomHeight = CGFloat(arc4random() % maxHeight)
if (randomHeight < self.frame.size.height*0.1) {
randomHeight = self.frame.size.height*0.12
}
self.enemyBird.position = CGPointMake(self.frame.size.width+100,randomHeight)
score++
self.scoreLabel.text = "\(score)"
}
let moveToEndThenStartAgain = SKAction.repeatActionForever(SKAction.sequence([moveToEndAction,resetTostartAction]))
enemyBird.runAction(SKAction.repeatActionForever(moveToEndThenStartAgain))
enemyBird.position = CGPointMake(self.frame.size.width+100, 500)
movingObjects.addChild(enemyBird)
// ENEMY BIRD TWO
var waitBird2 = SKAction.waitForDuration(0.75)
var waitBird2run = SKAction.runBlock({
// Random Height
let maxHeight2:UInt32 = UInt32(self.frame.size.height - self.enemyBird.size.height)
let moveToEndAction2 = SKAction.moveToX(0, duration: 1.5)
let resetTostartAction2 = SKAction.runBlock { () -> Void in
var randomHeight2 = CGFloat(arc4random() % maxHeight2)
if (randomHeight2 < self.frame.size.height*0.1) {
randomHeight2 = self.frame.size.height*0.12
}
self.enemyBird2.position = CGPointMake(self.frame.size.width+100,randomHeight2)
score++
self.scoreLabel.text = "\(score)"
}
let moveToEndThenStartAgain2 = SKAction.repeatActionForever(SKAction.sequence([moveToEndAction2,resetTostartAction2]))
self.enemyBird2.runAction(SKAction.repeatActionForever(moveToEndThenStartAgain2))
self.enemyBird2.position = CGPointMake((self.frame.size.width+100), 200)
})
var bird2Seq = SKAction.sequence([waitBird2, waitBird2run])
enemyBird2.runAction(bird2Seq)
enemyBird2.position = CGPointMake((self.frame.size.width+100), 500)
movingObjects.addChild(enemyBird2)
}
下面的行是两个敌人产生的代码块中需要更改的内容:
let moveToEndAction = SKAction.moveToX(0 - enemyBird.size.width, duration: 1.5)
我希望持续时间基于我可以根据分数改变的变量。