简体   繁体   中英

Type 'GameScene has no member 'delay'

I declared delay and it is giving me an error, I am trying to slow down the timer.

//Updates Timer
    func updateTimer() {
        var delay: Int
        seconds  += 1
        self.timerLabel.text = String(self.seconds * 0.01)
        timer = NSTimer.scheduledTimerWithTimeInterval(-2.0, target: self, selector: #selector(GameScene.delay), userInfo: nil, repeats: false)

the selector portion of a NSTimer is meant to run a function so you declare the function then the timer should be placed outside of the function instead of inside the function

func updateTimer() {
    var delay: Int
    seconds  += 1
    self.timerLabel.text = String(self.seconds * 0.01)}
let timer = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: #selector(self.updateTimer), userInfo: nil, repeats: false)

also could you be more specific when you say you are trying to slow down the timer so

The message is telling you that there is no selector for GameScene.delay . You need a func that matches this name. Note that because you have used "GameScene" rather than "gameScene", it may be a class, in which case you would need a "class func" called delay. However, more likely is you would want "self.delay" to be called. ie. one of

    func delay(timer: NSTimer) { ... }
    class func delay(timer: NSTimer) { ... }

Also, what are you trying to achieve with "-2.0"? You can't run a timer in the past - if will default to 0.1 if <= 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM