Search code examples
iosswiftsprite-kitskaction

SKAction.wait causing Extra Argument in Call Error


I am attempting to animate and code a text label, however using the SKAction.wait(:) function causes an extra argument in call error. Here is my code. I have no other errors, and my other SKAction functions are working fine:

import SpriteKit
import GameplayKit

class GameScene: SKScene {

    private var label : SKLabelNode?


    override func didMove(to view: SKView) {

        // Get label node from scene and store it for use later
        self.label = self.childNode(withName: "//helloLabel") as? SKLabelNode
        if let label = self.label {
            label.alpha = 0.0
            label.run(SKAction.fadeIn(withDuration: 2.0))

            var animateList = SKAction.sequence(SKAction.fadeIn(withDuration: 1.0), SKAction.wait(forDuration: 2.0), SKAction.fadeOut(withDuration: 1.0))

        }
    }
}

Solution

  • SKAction.sequence takes in an array as an argument. So your statement should read as follows

    var animateList = SKAction.sequence([SKAction.fadeIn(withDuration: 1.0), SKAction.wait(forDuration: 2.0), SKAction.fadeOut(withDuration: 1.0)])
    

    More details here