2

In my game I have a SpriteNode running an endless animation; the user can stop the animation by hitting a button (resume as well); I need to know the current frame of the animation, so I can read the proper value associated with it (from an XML file).

Here is my code:

SKAction *animateCircle = [SKAction
                         animateWithTextures:_animationTextures
                         timePerFrame: [self getAnimationSpeedAccordingToStage]];
    SKAction *repeatAnimation = [SKAction repeatActionForever:animateCircle];
    [shapeNode runAction:repeatAnimation withKey:@"shapeAnimation"];
    animationStartTime = [NSDate date];
    [self resumeShapeAnimation];
Sled
  • 18,541
  • 27
  • 119
  • 168
tperei
  • 353
  • 2
  • 8
  • possible duplicate of [SKTexture get image name](http://stackoverflow.com/questions/21698512/sktexture-get-image-name) – jackslash Feb 13 '14 at 00:37

1 Answers1

0

Are your animation textures numbered? If they follow a pattern like textureNameNumber you can use this solution that I myself used:

  -(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;
}
LucasMW
  • 151
  • 6