iPhone- Spritekit Programming: Loading Scene from Button
-
21-12-2019 - |
Question
I am new to the spritekit system. However, I have some questions. I have an app that has a menu screen, instructions page, etc..., none of which recquire me loading a skcene. However, I want to be able to load my "Game" scene on the press of a button. How would I do that regarding code?
FIXED:
I just did not check the IB settings for one of my views: my view type should be SKView.
Solution
Create new SKView in your view controller's -viewDidLoad: method
SKView *spriteView = (SKView *) self.view;
Then create new SKScene class in a separate file
@interface GameScene : SKScene @end
Return to your previous view controller and place this code in your button's event handler
GameScene* scene = [[GameScene alloc] initWithSize:CGSizeMake(768,1024)]; SKView *spriteView = (SKView *) self.view; [spriteView presentScene: scene];
More info in Apple's documentation.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow