I have created a Test Scene to practice some basic Swift 3 and SpriteKit. I'm trying to learn by understanding the basics before moving on to more complex goals.
Here I have a SKLabelNode that is created and then moves to the left. I have created a sequence to repeat the action but it does not work. Please could you help me understand where it fails. NodeCount notes that there is only 1 node.
import SpriteKit
import GameplayKit
class GameScene: SKScene {
var testShape = SKLabelNode()
override func didMove(to view: SKView) {
func createShape() {
testShape = SKLabelNode(text: "TEST")
testShape.position = CGPoint(x: 0.5, y: 0.5)
testShape.zPosition = 1
addChild(testShape)
}
let moveTestShape = SKAction.moveBy(x: -500, y: 0, duration: 5)
func repeater() {
createShape()
testShape.run(moveTestShape)
}
let delay = SKAction.wait(forDuration: 2)
let repeatingAction = SKAction( repeater() )
let sequence = SKAction.sequence([ delay, repeatingAction ] )
run(SKAction.repeatForever(sequence))
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func update(_ currentTime: TimeInterval) {
}
}