Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone NSTimer没有开火_Cocos2d Iphone_Xcode4.5_Nstimer - Fatal编程技术网

Cocos2d iphone NSTimer没有开火

Cocos2d iphone NSTimer没有开火,cocos2d-iphone,xcode4.5,nstimer,Cocos2d Iphone,Xcode4.5,Nstimer,我所有的东西都运转良好,计时器也在运转。但当我遇到奇怪的问题时,我不得不重新构建我的cocos2d场景。 现在我再也不能发射NSTimer了,下面的BonusTimetimer甚至没有发射过一次 提前感谢,下面是代码 BonusTimeTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(CountTimeBonus:) userInfo:nil repeats:YES]; // (

我所有的东西都运转良好,计时器也在运转。但当我遇到奇怪的问题时,我不得不重新构建我的cocos2d场景。 现在我再也不能发射NSTimer了,下面的BonusTimetimer甚至没有发射过一次

提前感谢,下面是代码

BonusTimeTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(CountTimeBonus:) userInfo:nil repeats:YES];
// (lately i added the line below, but it does not help)
[[NSRunLoop mainRunLoop] addTimer:BonusTimeTimer forMode:NSDefaultRunLoopMode];


-(void)CountTimeBonus:(NSTimer *) sender {
    NSLog (@"Method -> Countimebonus");
    if ( (scoreTotal + 37) < TargetScore){
        scoreTotal = scoreTotal + 37;
        TimeBonus = TimeBonus-37;
        NSString *level_timebonus = [NSString stringWithFormat:@"%d", TimeBonus];
        [labelTimeBonus setString: level_timebonus];
        NSString *scorestr = [NSString stringWithFormat:@"%d", scoreTotal];
        [labelMainScore setString: scorestr];
        [[SimpleAudioEngine sharedEngine] playEffect:@"light_switch_.mp3"];
    }
    else {
        // add the Last few points and finish BonusTimer
        scoreTotal = scoreTotal + TimeBonus;
        TimeBonus=0;
        NSString *level_timebonus = [NSString stringWithFormat:@"%d", timebonusgrayed];
        [labelTimeBonus setString: @"" ];
        [labelTimeBonusGrayed setString: level_timebonus];
        NSString *scorestr = [NSString stringWithFormat:@"%d", scoreTotal];
        [labelMainScore setString: scorestr];
        [[SimpleAudioEngine sharedEngine] playEffect:@"light_switch_.mp3"] ;
        [BonusTimeTimer invalidate];
        BonusTimeTimer = nil;
        timeBonusisdone = true;
        timeBonusisactive = false;
    }
bonustimeter=[NSTimer scheduledTimerWithTimeInterval:0.01目标:自选择器:@selector(CountTimeBonus:)用户信息:无重复:是];
//(最近我在下面添加了一行,但没有帮助)
[[NSRunLoop mainlunloop]addTimer:bonustimeter forMode:NSDefaultRunLoopMode];
-(无效)CountTimeBonus:(NSTimer*)发件人{
NSLog(@“方法->计数奖金”);
如果((总分+37)

}

我从来没有真正钻出过兔子洞(即为什么会这样),但一直有传言说NSTimer和cocos2d的配合不好。相反,我使用cocos自己的方法

[self schedule:@selector(CountTimeBonus:) interval:.01];

// and to invalidate this


[self unschedule:@selector(CountTimeBonus:)];
CountTimeBonus签名将为:

-(void) CountTimeBonus:(ccTime) dt {
}

我从来没有真正钻过那个兔子洞(即为什么会这样),但一直有传言说NSTimer和cocos2d不太合拍。相反,我使用cocos自己的方法

[self schedule:@selector(CountTimeBonus:) interval:.01];

// and to invalidate this


[self unschedule:@selector(CountTimeBonus:)];
CountTimeBonus签名将为:

-(void) CountTimeBonus:(ccTime) dt {
}

谢谢YvesLeBorg为我工作

<>有更多的事情要考虑,

1) cocos2d代码:

[self schedule:@selector(myTimer:) delay:.01];
有语法问题,我改为使用此选项(如下所示):

2) 我让NSTimer再次工作,但当我将NSTimer调用放入do while循环时,它将不工作

再次感谢,祝你好运


约翰

感谢伊夫斯勒堡为我工作

<>有更多的事情要考虑,

1) cocos2d代码:

[self schedule:@selector(myTimer:) delay:.01];
有语法问题,我改为使用此选项(如下所示):

2) 我让NSTimer再次工作,但当我将NSTimer调用放入do while循环时,它将不工作

再次感谢,祝你好运


Johan

Cocos2d的计时器在游戏暂停时也能正常工作,例如暂停射击。使用cocos2d的计时器是一个很好的建议。谢谢你的帮助,对我来说。康斯迪德还有几件事,1)代码:[自我计划:@selector(CountTimeBonus:)delay:.01];如果出现语法问题,请改用此选项(如下):[self schedule:@selector(CountTimeBonus:)interval:.01];2) thks,我更新了答案,这样其他人就不必弄明白了:)例如,如果游戏暂停,Cocos2d的计时器也会像你预期的那样工作(即暂停发射)。使用cocos2d的计时器是一个很好的建议。谢谢你的帮助,对我来说。康斯迪德还有几件事,1)代码:[自我计划:@selector(CountTimeBonus:)delay:.01];如果出现语法问题,请改用此选项(如下):[self schedule:@selector(CountTimeBonus:)interval:.01];2) thks,我更新了答案,这样其他人就不用想了:)