我是Swift和SpriteKit的新手,我遇到了一个小问题。我想每秒产生一次敌人,同时每帧稍微移动玩家一次。所以我尝试创建两个单独的SKActions。这是我的代码:
runAction(SKAction.repeatActionForever(
SKAction.sequence([
SKAction.runBlock(
addEnemy
),
SKAction.waitForDuration(1.0)
])
))
runAction(SKAction.repeatActionForever(
SKAction.runBlock(
movePlayer
)
))
但是当我执行上述操作时,都不会发生任何操作。我该如何解决这个问题?
答案 0 :(得分:0)
你需要写self.addEnemy()
& self.movePlayer()
就眼睛来说,我会像这样编写代码:
var waitE = SKAction.waitForDuration(1)
var runE = SKAction.runBlock{
self.addEnemy()
}
var runP = SKAction.runBlock{
self.movePlayer()
}
var repeatMovingPlayer = SKAction.repeatActionForever(runP)
var EnemySeqence = SKAction.seqence([waitE, runE])
var repeatAddingEnemy = SKAction.repeatActionForever(EnemySeqence)
self.runAction(repeatAddingEnemy)
self.runAction(repeatMovingPlayer)