2015-08-25 174 views
1

不改變我創建了一個遊戲,現在我想加入,我想運行一個視頻的開始屏幕,之後會出現與啓動按鈕的畫面,我已經搜查了互聯網,但找不到辦法,嘗試了很多東西,最新的代碼是:場景在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錯誤。你能告訴我怎麼做嗎?

+3

請提供錯誤的詳細信息 – aramusss

+0

終止應用程序(當它引起的,顯示錯誤文本等),由於未捕獲的異常「NSInvalidArgumentException」,原因:「*** - [NSPlaceholderdata initWithContentOfFile:選項:錯誤:]:無文件arguement」 – user3921943

回答

0

您應該檢查幾件事情,以確保一切都好有:

  • 檢查一切正常使用的文件名,尋找空間或錯別字等...
  • 看到什麼pathForResource回報率(的println它)
  • 看看有什麼fileURLWithPath返回
  • 轉到:目標 - >構建階段 - >複製束資源並在其中添加Intro.mp4文件。如果這個文件已經被添加,刪除,清理項目工程 - >乾淨,然後再重新添加。建立項目並運行它。
+0

yeahh ......這就是爲我工作。非常感謝@whirlwind – user3921943