Search code examples
swiftsprite-kitswift2skscene

Swift SpriteKit "Extra Arguement "size" in call


When trying to transition between a SKScene to another SKScene. For example when its game over I use the code below and get the following error:-

Extra Arguement "size" in call

Below is a sample of my code used when this error occurs.

let scene = GameOverScreen(size: self.scene!.size) //<<---- Error throws here
scene.scaleMode = SKSceneScaleMode.AspectFill
view!.scene?.paused = true

self.scene!.view!.presentScene(scene, transition: transition)

This has never happened before in previous games of mine, and I cant seem to figure out why?

Using XCode 7, swift 2 and SpriteKit

Thanks in advance,

Rachel


Solution

  • I'm guessing this is happening because you have other initializers defined in GameOverScene that you haven't mentioned. Since you do that, you don't automatically inherit all of SKScene's initializers. You probably just have to add the following to GameOverScene:

    override init(size: CGSize) {
        // Set up your properties
        super.init(size: size)
    
        // Do whatever else you need to
    }
    

    If you didn't have any initializers defined in GameOverScene, you wouldn't be seeing this behavior. I'd suggest doing some further reading on Automatic Initializer Inheritance. The section I've linked to on that page describes the rules for when a class inherits the initializers of a superclass. They are not inherited by default.