Текущий кадр анимации — SKSpriteNode

В моей игре есть SpriteNode с бесконечной анимацией; пользователь может остановить анимацию, нажав кнопку (также возобновить); Мне нужно знать текущий кадр анимации, чтобы я мог прочитать правильное значение, связанное с ним (из XML-файла).

Вот мой код:

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

person HeavenlyManBR    schedule 13.02.2014    source источник
comment
возможный дубликат SKTexture получить имя изображения   -  person jackslash    schedule 13.02.2014


Ответы (1)


Анимационные текстуры пронумерованы? Если они следуют такому шаблону, как 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;
}
person LucasMW    schedule 23.03.2015