2013-10-08 13 views
5

Kiedy nie używam atlasu tekstury, wszystko działa poprawnie. Ale kiedy używam atlasu tekstury, animateWithTextures nie działa i nic nie pojawia się. Oto mój kodSpriteKit animateWithTextures nie działa z teksturą atlas

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

czy obejrzałeś tutaj: http://stackoverflow.com/questions/19159537/ios-spritekit-animation-does-not-appear i tutaj http://www.raywenderlich.com/45152/sprite-kit-tutorial -animacje-i-tekstury-atlasy – DogCoffee

+1

@Smick Dziękuję. Znalazłem tam odpowiedź. –

Odpowiedz

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

to rozwiązać mój problem.

+0

To też mi pomogło. runAction() spowodował awarię aplikacji z EXE_BAD_ACCESS przed załadowaniem wstępnych tekstur. Dzięki! – Brainware

+0

Miałem problem z 'repeatActionForever:', który spowodował awarię i to naprawiło. – Alexander

Powiązane problemy