参数“coder”在调用中丢失的参数

时间:2021-05-22 09:40:46

Im am trying to pause or stop an SKAction that is being repeated forever which should happen when the user presses the pause button. 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.

我正在尝试暂停或停止一个SKAction,这个SKAction会一直重复,当用户按下暂停按钮时就会发生。我找到了停止音乐的方法,但是由于这个错误,我不能调用它所在的函数。它确切地说:在调用中缺少参数“coder”的参数。

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")
    }
 }

1 个解决方案

#1


1  

There is no initializer for GameScene that takes no arguments - you haven't defined one nor is one inherited from 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初始化器——您没有定义一个参数,也没有从SKScene继承一个参数。如果您打算在每次“暂停”时创建一个GameScene,这本身就是一个有问题的方法,那么您需要调用一个现有的初始化器,或者创建一个初始化器w/o任何参数。

It looks like the designated initializer for SKScene is init(size: CGSize). So instead of simply calling GameScene() call GameScene(size: ...) or, in the class GameScene define

看起来SKScene的指定初始化器是init(size: CGSize)。因此,不要简单地调用GameScene()调用GameScene(size:…),或者在GameScene define类中

class GameScene : SKScene {
  // ... 

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

#1


1  

There is no initializer for GameScene that takes no arguments - you haven't defined one nor is one inherited from 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初始化器——您没有定义一个参数,也没有从SKScene继承一个参数。如果您打算在每次“暂停”时创建一个GameScene,这本身就是一个有问题的方法,那么您需要调用一个现有的初始化器,或者创建一个初始化器w/o任何参数。

It looks like the designated initializer for SKScene is init(size: CGSize). So instead of simply calling GameScene() call GameScene(size: ...) or, in the class GameScene define

看起来SKScene的指定初始化器是init(size: CGSize)。因此,不要简单地调用GameScene()调用GameScene(size:…),或者在GameScene define类中

class GameScene : SKScene {
  // ... 

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