2011-12-17 47 views
1

我編寫了一個演示應用程序,該應用程序可以在模擬器上完美工作,但是當我將它放在實際設備上時,骰子會跳過。以視頻爲例。重新啓動應用程序後,動畫很好。大約1分鐘重複敲擊滾動按鈕發生錯誤。Cocos2d精靈CCAnimation僅在設備上移動時跳過

http://youtu.be/N1k1QPa1brg

的代碼是所有住在:

https://github.com/rnystrom/MartionDemo 如何使骰子對象的動畫:

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

事實證明這是一個performSelector:afterDelay:問題。我通過爲延遲添加一些填充時間來解決它,所以事情不會同時發生。

我也放了一個塊,以便只有在動畫完成後才能執行動作。在中斷CCMoveTo-esque動畫時,似乎存在某種問題。