简体   繁体   English

Swift-呼叫中缺少参数“编码器”的参数

[英]Swift - Missing argument for parameter “coder” in call

Im am trying to pause or stop an SKAction that is being repeated forever which should happen when the user presses the pause button. 我正在尝试暂停或停止永远重复的SKAction,这将在用户按下暂停按钮时发生。 I have found a way to stop the music but i cant call the function it is in because of this error. 我已经找到一种停止音乐的方法,但是由于此错误,我无法调用该函数。 It says exactly: Missing argument for parameter 'coder' in call . 它确切地说: Missing argument for parameter 'coder' in call

Class GameViewController: UIViewController, SwiftrisDelegate, UIGestureRecognizerDelegate     {

    @IBAction func didPause(sender: UIButton) {
        if self.scene.paused == false{
            self.scene.stopTicking()
            self.scene.paused = true
            GameScene().stopGameMusic() //error on this line
        }
    }
}

class GameScene: SKScene {

    runAction(SKAction.playSoundFileNamed("theme.mp3", waitForCompletion: true), withKey:("themeSong"))

    func stopGameMusic() {
        removeActionForKey("themeSong")
    }
 }

There is no initializer for GameScene that takes no arguments - you haven't defined one nor is one inherited from SKScene . GameScene没有任何不带参数的初始化程序-您尚未定义一个,也不是从SKScene继承的。 If you intend to create a GameScene each time 'pause' is pushed, which is a questionable approach in itself, then you'll need to call an existing initializer or to create an initializer w/o any arguments. 如果您打算在每次按下“暂停”时创建一个GameScene ,这本身就是一个有问题的方法,那么您将需要调用现有的初始化程序或创建一个不带任何参数的初始化程序。

It looks like the designated initializer for SKScene is init(size: CGSize) . 看起来SKScene的指定初始化SKSceneinit(size: CGSize) So instead of simply calling GameScene() call GameScene(size: ...) or, in the class GameScene define 因此, GameScene()简单地调用GameScene() GameScene(size: ...)调用GameScene(size: ...)或在GameScene类中定义

class GameScene : SKScene {
  // ... 

  init () {
    super.init (size: ...)
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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