Search code examples
iosios7sprite-kitscale

SpriteKit scaleTo action scaling issue


I'm trying to make a node scale down to a small size, move down, and then once all that happens animate it repeatedly (at the same scaled down size with a different texture).

Here is my method that scales the node down and moves it. That part is working correctly. However once it finishes doing that I need to change the sprites texture and animate it.

- (void)shrinkAndMoveToPosition:(CGPoint)position {

    SKAction *move = [SKAction moveTo:position duration:.5];
    SKAction *scale = [SKAction scaleTo:.3 duration:.5];
    SKAction *moveAndScale = [SKAction group:@[move, scale]];
    [self runAction:moveAndScale completion:^{

        NSArray *textures = @[[SKTexture textureWithImageNamed:@"ship-small_01"],
                              [SKTexture textureWithImageNamed:@"ship-small_02"],
                              [SKTexture textureWithImageNamed:@"ship-small_03"],
                              [SKTexture textureWithImageNamed:@"ship-small_04"]];

        SKAction *animate = [SKAction animateWithTextures:textures timePerFrame:0.5];

        [self runAction:[SKAction repeatActionForever:animate]];

    }];


}

The problem is that whenever my completion block runs the sprite jumps back up to the size of the texture. How can I maintain my scaled down size?


Solution

  • I just needed to call a different animate method and pass in YES to the resize parameter:

    SKAction *animate = [SKAction animateWithTextures:textures timePerFrame:0.5 resize:YES restore:NO];