I am having an issue with an SKAction sequence I set up.
The goal of this sequence is to take an array of 9 sprite nodes and display one at a time. This sequence will then show the node to the right or to the left of the current node depending on which button is pressed (right button or left button).
I am experiencing something interesting here. It seems to work as it is now, but if I press button left or button right multiple times fast, it seems like it cannot keep up and the process fails. I don't get an error, the sprite nodes just don't display or don't display correctly.
I have attached my code below. Because it is working when I cycle through slowly, I believe it is a timing issue and maybe I need to add a completion block. I tried doing this but was unsuccessful.
My question is, does anything obvious stick out that looks wrong here and do you think a completion block could possibly solve the issue?
func pressedButtonRight(){
if currentDisplayedWorld < 8 {
var currentWorld:SKSpriteNode = worldArray[currentDisplayedWorld] as SKSpriteNode
var nextWorld:SKSpriteNode = worldArray[currentDisplayedWorld + 1] as SKSpriteNode
nextWorld.position = CGPointMake(self.frame.size.width, 50)
self.addChild(nextWorld)
let move = SKAction.moveByX(-self.frame.size.width, y: 0,
duration: 1.0, delay: 0,
usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5)
//currentWorld.runAction(move)
nextWorld.runAction(move)
currentWorld.removeFromParent()
currentDisplayedWorld++
}else if currentDisplayedWorld == 8 {
}
}
func pressedButtonLeft(){
if currentDisplayedWorld > 0 {
var currentWorld:SKSpriteNode = worldArray[currentDisplayedWorld] as SKSpriteNode
var previousWorld:SKSpriteNode = worldArray[currentDisplayedWorld - 1] as SKSpriteNode
previousWorld.position = CGPointMake(-self.frame.size.width, 50)
self.addChild(previousWorld)
let moveBack = SKAction.moveByX(self.frame.size.width, y: 0,
duration: 1.0, delay: 0,
usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5)
//currentWorld.runAction(moveBack)
previousWorld.runAction(moveBack)
currentWorld.removeFromParent()
currentDisplayedWorld--
}else if currentDisplayedWorld == 0 {
}
}