SpriteKit 中的场景没有改变

Scene not changing in SpriteKit

我已经创建了一个游戏,现在我想添加一个开始屏幕,我想在其中 运行 一个视频,之后会有一个带有开始按钮的屏幕,我在互联网上搜索过但找不到方法,试了很多东西,最新的代码是:

#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

应用程序刚刚启动并给出 SIGABRT 错误。你能告诉我怎么做吗?

您应该检查几项以确保一切正常:

  • 检查文件名是否一切正常,查找空格或拼写错误等...
  • 查看pathForResource是什么returns(打印出来)
  • 看什么fileURLWithPathreturns
  • 转到:Target -> Build Phases -> Copy Bundle Resources 并在那里添加 Intro.mp4 文件。如果该文件已添加,请将其删除,清理您的项目 Project->Clean,然后再次添加。构建项目并 运行 它。