5

当我不使用纹理图集时,一切正常。但是当我使用纹理图集时,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];
4

1 回答 1

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

这解决了我的问题。

于 2013-10-09T03:45:06.620 回答