选择器不会返回到init

时间:2014-04-03 13:23:31

标签: objective-c cocos2d-iphone

我试图创建一个起始等级标签(例如3.2.1.GO),但是当我按照游戏状态安排选择器运行,并且如果游戏状态大于X则取消预定时,选择器不会; t返回到初始选择器,游戏仍然停止。

这是我在init方法上定义的代码:

if (startLevelAnimState <=4) {
        [self schedule: @selector(startLevelAnimation) interval:.5];
        NSLog(@"%d", startLevelAnimState);
    } else {
        [self unschedule:@selector(startLevelAnimation)];
    }

这是startLevelAnimation

-(void)startLevelAnimation {
    NSLog(@"running startlevelanimation");


    if (startLevelAnimState == 0) {
         NSLog(@"create start level label");
        startLevelLabel = [CCLabelTTF labelWithString:@"3" fontName:@"Verdana-Bold" fontSize:62];
        startLevelLabel.position = ccp(winWidth/2, winHeight*2);

        [self addChild:startLevelLabel z: 10];


        CCAction *actionMove = [CCActionMoveTo actionWithDuration:.8 position:CGPointMake(winWidth/2, winHeight*(.65))];
        //CCAction *actionRemove = [CCActionRemove action];
        [startLevelLabel runAction:[CCActionSequence actionWithArray:@[actionMove]]];
        startLevelAnimState ++;

    } else if (startLevelAnimState ==1) {
        [startLevelLabel setString: [NSString stringWithFormat:@"2"]];
        startLevelAnimState ++;

    } else if (startLevelAnimState ==2) {
        [startLevelLabel setString: [NSString stringWithFormat:@"1"]];
        startLevelAnimState ++;

    } else if (startLevelAnimState ==3) {
        [startLevelLabel setString: [NSString stringWithFormat:@"GO!"]];
        startLevelAnimState ++;

    } else if (startLevelAnimState ==4) {
        CCAction *actionMove = [CCActionMoveTo actionWithDuration:.8 position:CGPointMake(winWidth/2, winHeight*2)];
        [startLevelLabel runAction:[CCActionSequence actionWithArray:@[actionMove]]];
        startLevelAnimState ++;
        gameState = 1;
        [self unschedule:@selector(startLevelAnimation)];

    }

}

1 个答案:

答案 0 :(得分:1)

您需要将状态设置为0而不是递增。不是很明显吗?

} else if (startLevelAnimState ==4) {
    CCAction *actionMove = [CCActionMoveTo actionWithDuration:.8 position:CGPointMake(winWidth/2, winHeight*2)];
    [startLevelLabel runAction:[CCActionSequence actionWithArray:@[actionMove]]];
    startLevelAnimState = 0;
    gameState = 1;
    [self unschedule:@selector(startLevelAnimation)];

}