5

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'

Stefan
  • 5,203
  • 8
  • 27
  • 51
Mahdi Amrollahi
  • 2,930
  • 5
  • 27
  • 37
  • Can you add the error message ? – Stefan Jan 20 '16 at 21:19
  • 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' – Mahdi Amrollahi Jan 21 '16 at 02:40

1 Answers1

3

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).

enter image description here

In my example I've created a custom class GameMainView which inherits from SKView.

Stefan
  • 5,203
  • 8
  • 27
  • 51