When I don't use texture atlas,everything works fine.But when I use texture atlas,animateWithTextures doesn't work and nothing appears. Here is my code
SKTexture *spaceshipTexture = [SKTexture textureWithImageNamed:@"monkey.png"];
SKSpriteNode *spaceship = [SKSpriteNode spriteNodeWithTexture:spaceshipTexture];
spaceship.position = CGPointMake(0,0);
spaceship.anchorPoint = CGPointMake(0,0);
[self addChild: spaceship];
NSMutableArray *images=[NSMutableArray arrayWithCapacity:14];
for (int i=1; i<=14; i++) {
NSString *fileName=[NSString stringWithFormat:@"%dShuGuangx.png",i];
SKTexture *tempTexture=[SKTexture textureWithImageNamed:fileName];
[images addObject:tempTexture];
}
NSLog(@"count %d",images.count);
SKAction *walkAnimation = [SKAction animateWithTextures:images timePerFrame:0.1];
[spaceship runAction:walkAnimation];
[SKTexture preloadTextures:images withCompletionHandler:^(void){
[spaceship runAction:walkAnimation];
}];
This solved my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With