ios - 当前动画帧-SKSpriteNode

标签 ios objective-c animation sprite-kit skaction

在我的游戏中,我有一个运行无尽动画的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];

最佳答案

您的动画纹理编号了吗?
如果他们遵循类似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;
}

关于ios - 当前动画帧-SKSpriteNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21742943/

相关文章:

iphone - 添加编译后ITK奇怪的错误

ios - 将 NSNumber 转换为 NSString 问题

ios - 动画在 ios Playground 中不起作用

ios - RestKit 附加数据响应

objective-c - 对象-C : Constantly observe changes to a property(double value) to trigger if's

ios - 如何在 Objective C 中为 float 的 UIView 设置动画

html - 我在 svg 文件中工作,动画在 firefox 中不起作用,我在图像标签中使用 svg

ios - 异常构建 gradle 任务 launchIosDevice

Objective-C 说明; -/+ 和 *var

ios - 使用 GPUImage 的模糊 View 动画