I updated Xcode to version 6. Since then I haven't been able to use the code that used to write in Xcode 5 using Objective C.
There are some new files: GameScene.h and GameScene.m and GameScene.sks insteadf of MyScene.h and MyScene.m
They load with:
-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */
}
instead of the usual
-(id) initWithSize: (CGSize)size {
}
I cannot use the code that i used to write in the initWithSize in the didMoveToView, it doesn't work as it should. And if i create a initWithSize myself, it doesn't work either.
Please help! :)
Because
-(void)didMoveToView:(SKView *)view ;
is a new optional protocol that has to be implemented regardless of whether you use it or not, and so you do not have to have a separate initialization for the Gamescene.m subclassSKScene
this method will be called immediately after a scene is presented by a view and the method is intended to be overridden in a subclass.There isn't much Apple Documentation around
initWithSize
but I did find a another question that maybe related to your question.Where is the right place to configure SKScene content in SpriteKit? - Discusses where is the correct place to configure your
SKScene
content and the chosen answer compares the differences and pros of using eitherinitWithSize:
anddidMoveToView:
.If you load your scene from SKS file you can't use initWithSize because it never gets called. In that case scene is initialized with initWithCoder.
About the question initWith... vs didMoveToView.That depends on what you want. Init is for initializing, but you should be aware that self.view is nil while scene's initialization, (read the SO link which @Popeye has provided).