Sprite Kit animateWithTextures lags

前端 未结 2 1652
粉色の甜心
粉色の甜心 2021-01-07 05:07

I\'m using texture atlases in my Sprite Kit game. I\'m creating SKTextureAtlas object and store it\'s textures in array for each animation. So when I need some

2条回答
  •  無奈伤痛
    2021-01-07 05:25

    had the same problem and I solved it in my game by not using atlases. So try this example:

    -(void)makePlayerAnimation:(SKSpriteNode *)player
    {
    SKTexture *texture1 = [SKTexture textureWithImageNamed:@"texture1.png"];
    SKTexture *texture2 = [SKTexture textureWithImageNamed:@"texture2.png"];
    SKTexture *texture3 = [SKTexture textureWithImageNamed:@"texture3.png"];
    
    
    SKAction *animationTextures = [SKAction animateWithTextures:@[texture1, texture2, texture3] timePerFrame:0.1];
    
    
    [player runAction:animationTextures];
    }
    

    When you wish to activate animation do this:

    [self makePlayerAnimation:myNode];
    

    or

    [self makePlayerAnimation:self.myNode];
    

    Just depends how you declared it. If you need to run animation forever, you can just add line at the end of previous method:

    SKAction *repeat = [SKAction repeatActionForever: animationTextures];
    

    Hope this helps.

提交回复
热议问题