내 작업이 정상적으로 수행되지 않는 이유는 무엇입니까? 저는 CCLayer에서 파생 된 수업을 듣습니다. 클래스cocos2d 스케줄러를 사용하여 타이머 조건을 두 번 전달했습니다.
//create an update method for keeping track of how long its been since an animation has played
[self schedule:@selector(playIdleAnimation:)];
를 초기화하는 그리고 그 방법은 내가 프로그램을 실행하려면 갈 때 콘솔 문은 조건이 두 번 전달되는 보여, 아직
//an update method that will play an idle animation after a random period of idleness
-(void) playIdleAnimation:(ccTime) dt {
//if the user isn't playing an animation, increment the time since last animation variable
if ([bodySprite numberOfRunningActions] == 0) {
timeSinceLastAnimation += (float)dt;
//now check to see if we have surpassed the time set to cause an idle animation
if (timeSinceLastAnimation > (arc4random() %14) + 8) {
//reset the cooldown timer
timeSinceLastAnimation = 0;
[bodySprite stopAllActions];
//play the idle animation
//[bodySprite runAction:[CCAnimate actionWithAnimation:waitAnimation restoreOriginalFrame:NO]];
NSLog(@"PLAYING IDLE ANIMATION");
}
}
//player is currently playing animation so reset the time since last animation
else
timeSinceLastAnimation = 0;
}
그러나 때 나는 같은 메소드 호출을 예약하고 각 재사용
012-06-29 09 : 52 : 57.667 게임 테스트 [5193 : 707] PLAYING IDLE ANIMATION
2012-06-29 09 : 52 : 57.701 게임 테스트 [5193 : 707] 재생하기 IDLE ANIMATION
2012-06-29 09 : 53 : 05.750 게임 테스트 [5193 : 707] PLAYING IDLE ANIMATION
2012-06-29 09 : 53 : 05.851 게임 테스트 [5193 : 707] IDLE ANIMATION
재생하기유휴 애니메이션을 재생할 때 게임이 멈추는 버그를 수정하려고합니다.이 게임과 관련이 있다고 확신합니다.
도움 주셔서 감사합니다.하지만 스케줄을 세우지 않으면 도움이되지 않았습니다. 일정 간격을 0.5 초마다 지정하여 문제를 해결할 수있었습니다. 그것이 두 번 부름을 받았던 이유는 여전히 수수께끼 일 것입니다. 아마도 예약 된 메서드가 스레드에서 실행됩니까? – user819640