2011-12-17 2 views
1

시뮬레이터에서 완벽하게 작동하는 데모 응용 프로그램을 작성했지만 실제 장치에 배치하면 주사위가 건너 뜁니다. 다음은 비디오를 예로 든 것입니다. 앱을 다시 시작하면 애니메이션이 정상적으로 작동합니다. 롤 버튼을 반복적으로 치는 약 1 분 동안 오류가 발생했습니다.장치에서만 이동할 때 CCAnimation이 건너 뛰는 Cocos2d 스프라이트

http://youtu.be/N1k1QPa1brg

코드는 모두 살에서 :

CCAnimation *anim = [CCAnimation animationWithFrames:frames delay:delay]; 
if(self.sprite){ 
    // Animate the sprite 
    [self.sprite runAction:[CCAnimate actionWithAnimation:anim restoreOriginalFrame:NO]]; 
} 

롤링 기능 :

-(void)roll 
{ 
    // Array that contains the new positions of dice 
    // Predetermine the position, check if that will be on top of other dice 
    NSMutableArray* checkPos = [NSMutableArray array]; 

    for(Dice* d in rollDiceArray){ 
     [d resetPosition];  

     // Select a random position within bounds 
     NSInteger x = arc4random() % 600 + 50; 
     NSInteger y = arc4random() % 600 + 150; 
     CGPoint location = CGPointMake(x, y); 

     // Check if die will touch other dice 
     while (! [self checkPositionWithPoint:location array:checkPos]) { 
      // If position overlaps another die, get a new position 
      // PROBLEM: This is O(infinity)! 
      x = arc4random() % 600 + 50; 
      y = arc4random() % 600 + 150; 
      location = CGPointMake(x, y); 
     } 

     // If position does not overlap, add it to array of positions to be checked 
     [checkPos addObject:[NSArray arrayWithObjects:[NSNumber numberWithInteger:x], [NSNumber numberWithInteger:y], nil]]; 

     // Animate the dice to a position 
     // Addition in the switch is for some randomness and correcting the animation's timing offset 
     NSInteger numberFrames; 
     float frameRate; 
     float mod = (float)(arc4random() % 60)/100; 
     switch (d.fileNum) { 
      case 0: 
       numberFrames = kRayFrames; 
       frameRate = numberFrames/24 + mod; 
       break; 
      case 1: 
       numberFrames = kRayFrames; 
       frameRate = numberFrames/24 + mod - 0.4; 
       break; 
      case 2: 
       numberFrames = kTankFrames; 
       frameRate = numberFrames/24 + mod + 0.2; 
       break; 
      case 3: 
       numberFrames = kChickenFrames; 
       frameRate = numberFrames/24 + mod; 
       break; 
      case 4: 
       numberFrames = kCowFrames; 
       frameRate = numberFrames/24 + mod + 0.2; 
       break; 
      case 5: 
       numberFrames = kHumanFrames; 
       frameRate = numberFrames/24; 
       break; 
      default: 
       break; 
     } 

     id action = [CCMoveTo actionWithDuration:frameRate position:location]; 
     id ease = [CCEaseOut actionWithAction:action rate:4.0]; 
     [d.sprite runAction:ease]; 
    } 
} 

답변

0
나는 주사위 객체의 애니메이션을 만드는 방법

https://github.com/rnystrom/MartionDemo

이것은 performSelector : afterDelay : 문제로 밝혀졌습니다. 지연 시간에 패딩 타임을 추가하여 문제를 해결 했으므로 상황이 동시에 발생하지 않았습니다.

애니메이션을 완료 한 후에 만 ​​작업을 수행 할 수 있도록 블록에 넣었습니다. CCMoveTo-esque 애니메이션을 방해 할 때 어떤 종류의 문제가있는 것 같습니다.

관련 문제