2012-07-29 15 views
0

我有下面的代碼(這應該是正確的):與cocos2d的調度方法選擇問題

- (void) loadIntro:(ccTime)unused { 
    [[GameManager sharedGameManager] runWithSceneID:kIntroScene]; // fade to the intro screen 
} 


- (void) loadAppScreen { 
    CCSprite *commodoreScreenLoaded = [CCSprite spriteWithFile:@"CommodoreLoadedApp.png"]; 
    useBackgroundImage(commodoreScreenLoaded); 
    [self addChild:commodoreScreenLoaded]; 
} 


- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInView: [touch view]]; 
    // location = [[CCDirector sharedDirector] convertToGL:location]; 

    CGRect mySurface = (CGRectMake(100, 100, 320, 480)); 
    if (CGRectContainsPoint(mySurface, location)) { 
     //[[CCDirector sharedDirector] stopAnimation]; 
     play(@"InsertGameCartridge.wav"); 

     [self removeChild:commodoreScreen cleanup:YES]; 
     [self loadAppScreen]; 
     [self schedule:@selector(loadIntro:) interval:2.5f]; // <-- Right here! 
} 

但是當我運行它,它會記錄一個非常奇怪的錯誤:

2012-07-29 12:21:41.186 Apocanaut[7299:707] *** Assertion failure in -[CCTimer initWithTarget:selector:interval:repeat:delay:],/Users/chris/src/Apps/Games/Apocanaut/Apocanaut/libs/cocos2d/CCScheduler.m:111 

2012-07-29 12:21:41.190 Apocanaut[7299:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Signature not found for selector - does it have the following form? -(void) name: (ccTime) dt' 

編輯

它似乎來自GameManager類中的一種方法,我已經實現了一個名爲runWithSceneID的場景:

- (void) runWithSceneID:(SceneTypes)sceneID { 
    SceneTypes oldScene = currentScene; 
    currentScene  = sceneID; 
    id sceneToRun  = nil; 

    switch (sceneID) { 
     case kMenuScene: 
      sceneToRun = [MenuScene node]; 
      break; 

     case kCommodoreScene: 
      sceneToRun = [CommodoreScene node]; 
      break; 

     case kIntroScene: 
      sceneToRun = [IntroScene node]; 
      break; 

     default: 
      CCLOG(@"No scene ID to load"); 
      return; 
      break; 
    } 

    if (sceneToRun == nil) { 
     currentScene = oldScene; 
     return; 
    } 

    if ([[CCDirector sharedDirector] runningScene] == nil) { 
     [[CCDirector sharedDirector] runWithScene:sceneToRun]; 
    } else { 
     [[CCDirector sharedDirector] replaceScene: 
     [CCTransitionFade transitionWithDuration:kStandardTransitionDuration scene:sceneToRun]]; 
    } 
} 
+0

loadAppScreen'''方法的作用是什麼? – 2012-07-29 16:44:16

+0

@YannickL。添加。 :-) – beakr 2012-07-29 17:02:28

+0

@YannickL。我還添加了一個解釋GameManager方法'runWithSceneID'的新方法,它似乎是罪魁禍首。 – beakr 2012-07-29 17:06:38

回答

0

不確定爲什麼它有所作爲,但在某些情況下,這已經解決了這種性質的一些真正不透明的錯誤對我來說。聲明你的方法在一個私人類別中(MPBattleSequencer是我的場景之一,使用你自己的類):

@interface MPBattleSequencer (private) 

// snip-x-snip 

-(void) loadIntro:(ccTime)unused; 

@end