2014-02-13 47 views
2

在我的遊戲中,我有一個運行無盡動畫的SpriteNode;用戶可以通過點擊一個按鈕來停止動畫(簡歷);我需要知道動畫的當前幀,所以我可以讀取與其相關的適當值(來自XML文件)。當前動畫幀 - SKSpriteNode

這裏是我的代碼:

SKAction *animateCircle = [SKAction 
         animateWithTextures:_animationTextures 
         timePerFrame: [self getAnimationSpeedAccordingToStage]]; 
    SKAction *repeatAnimation = [SKAction repeatActionForever:animateCircle]; 
    [shapeNode runAction:repeatAnimation withKey:@"shapeAnimation"]; 
    animationStartTime = [NSDate date]; 
    [self resumeShapeAnimation]; 
+0

可能重複http://stackoverflow.com/questions/21698512/sktexture-get-圖像名稱) – jackslash

回答

0

是你的動畫紋理編號的? 如果他們遵循類似textureNameNumber您可以使用此解決方案,我自己使用的模式:

-(int) getAnimationFrameFromTexture: (SKTexture*) texture imageName:(NSString*) name 
{ 
    NSString* textureString = [NSString stringWithFormat:@"%@", texture]; 
    int i; 
    char numberStr[4]="000"; 
    for(i=0 ;i<[textureString length]; i++) 
    { 
     char character = [textureString characterAtIndex:i]; 
     if(character=='\'') 
      break; //found ' 
    } 
    //Adds length 
    i+=[name length]+1; 
    for(int j=0;i<[textureString length];i++, j++) 
    { 
     char character = [textureString characterAtIndex:i]; 
     numberStr[j]=character; 
     if(character=='\'') 
      break; 
    } 
    numberFromString=[NSString stringWithUTF8String:numberStr]; 
    int number = [numberFromString intValue]; 
    return number; 
} 
[SKTexture取得圖片名稱(中