2

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.

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")
    }
 }
2
  • GameScene() creates a new instance of the class GameScene. Is it your intention to do that? Commented Jan 10, 2015 at 15:56
  • no, i didnt realise thats what it did. I am just trying to call the function within the GameScene class. Commented Jan 10, 2015 at 16:26

1 Answer 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.

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

class GameScene : SKScene {
  // ... 

  init () {
    super.init (size: ...)
  }
}
Sign up to request clarification or add additional context in comments.

6 Comments

ok thanks for your help. Instead of creating a GameScene every time the button is pressed, do you know of another way that i could pause or stop the music when the button is pressed?
You create a GameScene one time, probably as part of your GameViewController and then you reference that one thereafter. Of course, when you create it one time, you still need to use a proper initializer. What the proper initializer is will depend on how your define the GameScene class.
So how do I properly initialize it? (please bear with me I am new to swift)
ah ok, yeah ive done that already i just didnt that it was called initializing. Ive sorted out the issue of creating a new instance of the scene but the code i am using to stop the skaction from running isnt workin. any help?
Mark this question as 'answered' and post another question with the details of the new problem.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.