안녕하세요 친구 나는 30 분마다 생명을 추가하기 위해 카운트 다운 타이머가 필요합니다. 그래서 카운트 다운 타이머를 만들었지 만 그 통화에서만 실행 중입니다. 여기에 전 세계적으로 실행되는 타이머가 필요합니다. 뒷 배경에 응용하거나 유령이 몸을 돕는다면. 어떻게 캔디 크래시처럼 cocos2d에서 30 분 카운트 다운 타이머를 만들 수 있습니까?
이
이 경우NSTimer
를 사용하는 것이 적절하지 않은 내 코드
int hours, minutes, seconds;
NSTimer *timer;
- (void)updateCounter:(NSTimer *)theTimer {
if(secondsLeft > 0){
secondsLeft -- ;
// hours = secondsLeft/3600;
minutes = (secondsLeft % 3600)/60;
seconds = (secondsLeft %3600) % 60;
// myCounterLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
[self removeChild:Liveslable];
Liveslable=[CCLabelTTF labelWithString:[NSString stringWithFormat:@"lives left in %02d:%02d minuts",minutes, seconds] fontName:@"ArialMT" fontSize:25];
Liveslable.position=ccp(winSize.width/2, winSize.height/2-140);
[self addChild:Liveslable];
}
else{
secondsLeft = 1800;
}
}
-(void)countdownTimer{
secondsLeft = hours = minutes = seconds = 0;
if([timer isValid])
{
[timer release];
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
[pool release];
}
이 질문과 대답을 살펴보십시오. http://stackoverflow.com/questions/24040226/countdown-in-cocos2d/24041064#24041064 –
계속 업데이트되는 텍스트에 대해 비트 맵 글꼴을 사용하는 것이 좋습니다. Cocos2D는 타이머가 바뀔 때마다 런타임에 새로운 텍스처를 생성 할 것이기 때문에 예를 들어 타이머에 트루 타입 폰트를 사용하면 실제로 성능을 죽일 수 있습니다. –