SpriteKit animateWithTextures不适用于纹理图集

时间:2013-10-08 10:05:44

标签: ios objective-c cocoa-touch ios7 sprite-kit

当我不使用纹理图集时,一切正常。但是当我使用纹理图集时,animateWithTextures不起作用而且什么都没有出现。 这是我的代码

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];

1 个答案:

答案 0 :(得分:6)

[SKTexture preloadTextures:images withCompletionHandler:^(void){
        [spaceship runAction:walkAnimation];
    }];

这解决了我的问题。