0

I am new to Swift and SpriteKit, and I have a small problem. I would like to spawn enemies once per second, while moving the player slightly once per frame. So I tried to create two separate SKActions. This is my code:

runAction(SKAction.repeatActionForever(
        SKAction.sequence([
            SKAction.runBlock(
                addEnemy
            ),
            SKAction.waitForDuration(1.0)
        ])
    ))

runAction(SKAction.repeatActionForever(
    SKAction.runBlock(
        movePlayer
    )
))

But when I run the above, neither action(s) happen. How would I fix this?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Sarah Pierson
  • 149
  • 10
  • They shouldn't affect each other. Have you tried using NSTimer instead of `runAction` instead? – erdekhayser Dec 25 '14 at 17:30
  • My guess is that either this code is never called, or that the object these are called on are never allocated or are deallocated early. – erdekhayser Dec 25 '14 at 17:31
  • 1
    There's nothing wrong with this code. Perhaps posting `addEnemy` and `movePlayer` would be helpful. Did you try adding a breakpoint in one of these functions? – 0x141E Dec 25 '14 at 22:29

1 Answers1

0

You need to write self.addEnemy() & self.movePlayer()

And just for the Eye, I would write the code like that:

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)