0

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

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

1 回答 1

0

不知道为什么它会有所作为,但在某些情况下,这对我来说已经解决了一些这种性质的非常不透明的错误。在私有类别中声明您的方法(MPBattleSequencer 是我的场景之一,使用您自己的类):

@interface MPBattleSequencer (private)

// snip-x-snip

-(void) loadIntro:(ccTime)unused;

@end
于 2012-07-31T14:56:31.613 回答