Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

init var with swift using SpriteKit?

How to correctly init with swift using SpriteKit?

This compiles but I get a error once the simulator starts running. "swift_reportUnimplementedInitializer"

import SpriteKit

class GameScene: SKScene {

    var paddlePositionUpdate:CGPoint

    init(paddlePositionUpdate:CGPoint){
    self.paddlePositionUpdate = CGPoint.zeroPoint
    super.init()
}
}
like image 321
Chéyo Avatar asked May 19 '26 12:05

Chéyo


1 Answers

The designated inititaliser for SKScene is init(size) where size is the size of your scene. You have attempted to use init() which does not exist.

You can see the exact method signature if you Cmd+click on SKScene...

EDIT: Try something like

class GameScene: SKScene {

    var paddlePositionUpdate: CGPoint

    init(size: CGSize, paddlePosition: CGPoint = CGPoint.zeroPoint){
        paddlePositionUpdate = paddlePosition
        super.init(size)
    }
}

A scene should be initialised with a size...

like image 148
Roshan Avatar answered May 23 '26 02:05

Roshan