OneTrueSen
OneTrueSen

Reputation: 13

Not calling the right scene objective c

Hi I'm pretty new to objective C and haven't worked much with the SpriteKit yet. I'm trying to figure out why my GameViewController isn't firing my MenuScene.m.

This is from my GameViewController

#import "MenuScene.h"

@implementation GameViewController

- (void)viewDidLoad {
[super viewDidLoad];

MenuScene* scene = (MenuScene*)[SKScene nodeWithFileNamed:@"MenuScene"];

// Set the scale mode to scale to fit the window
scene.scaleMode = SKSceneScaleModeAspectFill;

SKView *skView = (SKView *)self.view;

// Present the scene
[skView presentScene:scene];

skView.showsFPS = YES;
skView.showsNodeCount = YES;
}
@end

This is from my MenuScene.m

- (void)didMoveToView:(SKView *)view 
{
NSLog(@"In MenuScene.m");
CGSize playButtonSize = CGSizeMake(100, 100);
_playButton = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:playButtonSize];
_playButton.position = CGPointMake(self.size.height * .5, self.size.width*.5);
_playButton.name = @"playButtonNode";
_playButton.zPosition = 1.0;
[self addChild:_playButton];
}

What I get is a washed out grey color background with nothing else and nothing gets printed on the console so I know its not calling the didMoveToView method in my MenuScene.m. Also if I change this line

MenuScene* scene = (MenuScene*)[SKScene nodeWithFileNamed:@"MenuScene"];

to this

GameScene *scene = (GameScene *)[SKScene nodeWithFileNamed:@"GameScene"];

it will correctly call the didMoveToView method in the GameScene file. Sorry for the silly question but everything I try wont work.

Upvotes: 0

Views: 56

Answers (1)

matt
matt

Reputation: 534914

I'm going to guess that although your code casts [SKScene nodeWithFileNamed:@"MenuScene"] to a MenuScene, it is not in fact a MenuScene and so no MenuScene code runs.

Upvotes: 1

Related Questions