Can you tell me why this code doesn't work? Isn't it possible to run an Action in a SKAction.runBlock()-function?
let testaction = SKAction.repeatActionForever(SKAction.runBlock({self.myFunction()}))
runAction(testaction)
Here is my testaction:
func myFunction() {
runAction(SKAction.runBlock({
let i = 0
print(i)
}))
}
I need this for a game. I want to distinguish some cases in myFunction to run different Actions in different cases. What have i done wrong?
Edit: When i change myFunction() to this, i get printed the 1 forever, but not the 0 from the inside runBlock.
func myFunction() {
let j = 1
print(j)
runAction(SKAction.runBlock({
let i = 0
print(i)
}))
}
runAction
doesn't cause an action to run, it just queues an action to be run the next time the scene's animation loop is processed. I'm guessing that since you're constantly adding actions to that queue (without even any delay), that animation loop never gets processed. If you don't repeat that forever, but instead run X times, you'll see a bunch of 1s followed by a bunch of 0s. – Ben Kane