Reputation: 69
I'm relatively new to sprite kit and am making a simple game where a ball moves back and forth accrues the screen and moves down when the screen is tapped. I am unable to find a way to run two actions in sequence, repeatedly until the screen is tapped, where it will then start moving back and forth again.
let movePlayerForward = SKAction.moveToX(self.frame.width - Player.size.width / 2, duration: 2)
let movePlayerBack = SKAction.moveToX(Player.size.width / 2, duration: 2)
^ I need to run these two actions in sequence, repeatedly until the screen is tapped. Then start them up again.
Upvotes: 1
Views: 113
Reputation: 7324
Can you try this (Hints are in the code comments)?
let sequence = SKAction.sequence([movePlayerForward, movePlayerBack])
let player = SKSpriteNode(imageNamed: "player")
// start your action with repeating it forever
player.runAction(SKAction.repeatActionForever(sequence), withKey: "moveForwardBackward")
// stop your action after tapping
player.removeActionForKey("moveForwardBackward")
Upvotes: 1