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 に答える