cocos2d调度方法选择器的问题

时间:2012-07-29 14:57:01

标签: objective-c events cocos2d-iphone selector scheduler

我有以下代码(应该是正确的):

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

1 个答案:

答案 0 :(得分:0)

不确定为什么会有所作为,但在某些情况下,这已经为我解决了一些非常不透明的错误。在私有类中声明你的方法(MPBattleSequencer是我的一个场景,使用你自己的类):

@interface MPBattleSequencer (private)

// snip-x-snip

-(void) loadIntro:(ccTime)unused;

@end