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()
}
}
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With