Search code examples
iosios7sprite-kit

SKTexture returns wrong size?


I have an atlas of images, they are 80 by 80. But SKTexture says some of frames are 33x80 despite them clearly being 80x80. What is wrong? My animation looks very wrong when it runs.

Here is the code:

SKTextureAtlas *myAtlas = [SKTextureAtlas atlasNamed:@"my"];
NSInteger numberOfImages = [run.textureNames count];

NSLog(@"atlas: %@", myAtlas);

for (int i = 0; i < numberOfImages; i++) {
    NSString *textureName = [NSString stringWithFormat:@"walk%.2d", i];
    SKTexture *temp = [myAtlas textureNamed:textureName];
    [self.runningFrames addObject:temp];
}

Logging returns this:

<SKTextureAtlas> 'my' 16 textures:
 (
    "<SKTexture> 'walk00.png' (33 x 80)",
    "<SKTexture> 'walk01.png' (80 x 80)",
    "<SKTexture> 'walk02.png' (33 x 80)",
... omitted
)

Why is that? My animation goes completely out of hand, it shifts from side to side, etc.


Solution

  • I found a solution to the problem. I was animating using method

    [self.player runAction:[SKAction repeatActionForever:[SKAction animateWithTextures:self.runningFrames timePerFrame:0.05 resize:NO restore:YES]] withKey:@"playerRunning"];
    

    Changing resize to YES fixed all my problems.