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]];
    }
}

不确定为什么它会有所不同,但在某些情况下,它为我解决了一些这种性质的不透明错误。在私有类别中声明您的方法(MPBattleSequencer是我的场景之一,使用您自己的类):

@interface MPBattleSequencer (private)
// snip-x-snip
-(void) loadIntro:(ccTime)unused;
@end

最新更新