Search code examples
iosobjective-csprite-kitskscene

Scene not changing in SpriteKit


I've created a game and now I want to add a start screen in which I want to run a video and after that there will be a screen with start button, I've searched over internet but couldn't find out the way to do it, have tried many things, the latest code is:

#import "FirstScreen.h"
#import "GameScene.h"
#import <MediaPlayer/MediaPlayer.h>

@implementation FirstScreen

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        NSURL *url =[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Intro" ofType:@"mp4"]];
        _player = [[MPMoviePlayerController alloc] initWithContentURL:url];
        _player.view.frame = CGRectMake(0,0, 1024, 768);
        [self.view addSubview:_player.view];

        _player.shouldAutoplay = YES;
        [_player prepareToPlay];

        NSString *nextSceneButton;
        nextSceneButton = @"Start";

        SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];

        myLabel.text = nextSceneButton;
        myLabel.fontSize = 30;
        myLabel.fontColor = [SKColor blackColor];
        myLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
        myLabel.name = @"Start";

        [self addChild:myLabel];
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    SKNode *node = [self nodeAtPoint:location];

    if ([node.name isEqualToString:@"Start"]) {
        SKTransition *reveal = [SKTransition fadeWithDuration:3];

        GameScene *scene = [GameScene sceneWithSize:self.view.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
        [self.view presentScene:scene transition:reveal];
    }
}

@end

App just starts and give the SIGABRT error. Can you tell me how to do it?


Solution

  • You should check few things to make sure is everything okay there:

    • Check if everything is okay with file name, look for spaces or typos etc...
    • See what pathForResource returns (println it)
    • See what fileURLWithPath returns
    • Go to : Target -> Build Phases -> Copy Bundle Resources and add Intro.mp4 file there. If that file is already added , delete it, clean your project Project->Clean, and add it again. Build project and run it.