2013-10-08 7 views
5

Wenn ich keinen Texturatlas benutze, funktioniert alles gut. Aber wenn ich Texturatlas benutze, funktioniert animateWithTextures nicht und nichts erscheint. Hier ist mein CodeSpriteKit animateWithTextures funktioniert nicht mit Texturatlas

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

hast du hier geschaut: http://stackoverflow.com/questions/19159537/ios-spritekit-animation-does-not-appear und hier http://www.raywenderlich.com/45152/sprite-kit-tutorial -Animationen-und-Textur-Atlanten – DogCoffee

+1

@Smick Vielen Dank.Ich habe die Antwort gefunden. –

Antwort

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

Das ist mein Problem gelöst.

+0

Das hat mir auch geholfen. runAction() verursachte einen Absturz der App mit EXE_BAD_ACCESS, bevor ich die Texturen vorgeladen habe. Vielen Dank! – Brainware

+0

Ich hatte ein Problem mit 'repeatActionForever:' das verursachte einen Absturz und das behob es. – Alexander

Verwandte Themen