I want to develop a game with SpriteKit on Apple iOS platform.My game has a setting page that contains label,button,table view ,... and a game page.In my test, the first page is the setting and when player press "Start", the game will begin.I do not know how transfer to the game scene and i do not know where is my problem , perhaps because i am new to SpriteKit. My setting page is a start page in storyboard and by default it was connect to GameViewController and when i press the "Start" button , i get error at the last line and the program will stop. I want to load my game scene in a new view but i have problem. Here is my code:
-(IBAction)btn_startGame:(id)sender
{
SKView* skView = (SKView*)self.view;
SKScene* obj_gameScene = [MyScene sceneWithSize:skView.bounds.size];
obj_gameScene.scaleMode = SKSceneScaleModeAspectFill;
SKTransition *transition = [SKTransition flipVerticalWithDuration:0.5];
[skView presentScene:obj_gameScene];
}
This is the error:
2016-01-21 06:06:40.201 test_myGame[605:5321] -[UIView presentScene:]: unrecognized selector sent to instance 0x7fd809fcf570 2016-01-21 06:06:40.207 test_myGame[605:5321] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView presentScene:]: unrecognized selector sent to instance 0x7fd809fcf570'
You have to make sure that the view of your GameController is an SKView instead an UIView.
You can check in the storyboard:
Select the View of the ViewController (at the left side) and check the type (in the right side).
In my example I've created a custom class GameMainView which inherits from SKView.
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