Sprite Kit animateWithTextures lags

前端 未结 2 1635
粉色の甜心
粉色の甜心 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

    I am sure there are few ways to get around this. What you need to do is to preload an atlases before your gameplay actually start. Just show a loading screen at the beginning of the game and preload your atlases.

    You may try with + preloadTextureAtlases:withCompletionHandler:

    [SKTextureAtlas preloadTextureAtlases:textureAtlasesArray withCompletionHandler:^{ /*Game Start*/}];
    

    Another way to implement resource loading before everything else (and keep everything in memory) is described here in Adventure game example

    For more details about loading assets asynchronously take a peek into code which can be downloaded from the link above.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题