2013-10-08 10 views
5

Quando non uso atlante texture, tutto funziona bene. Ma quando uso atlante texture, animateWithTextures non funziona e non appare nulla. Ecco il mio codiceSpriteKit animateWithTextures non funziona con atlante texture

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

hai cercato qui: http://stackoverflow.com/questions/19159537/ios-spritekit-animation-does-not-appear e qui http://www.raywenderlich.com/45152/sprite-kit-tutorial -animations-and-texture-atlases – DogCoffee

+1

@Smick Grazie. Ho trovato la risposta lì. –

risposta

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

Questo risolto il mio problema.

+0

Anche questo mi ha aiutato. runAction() ha causato l'arresto anomalo dell'app con EXE_BAD_ACCESS prima di eseguire il precaricamento delle trame. Grazie! – Brainware

+0

Ho avuto un problema con 'repeatActionForever:' che ha causato un crash e questo l'ha risolto. – Alexander