2013-10-08 1 views
5

Когда я не использую текстурный атлас, все работает отлично. Но когда я использую атлас текстуры, animateWithTextures не работает и ничего не появляется. Вот мой кодSpriteKit 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]; 
+0

Вы смотрите здесь: http://stackoverflow.com/questions/19159537/ios-spritekit-animation-does-not-appear и здесь http://www.raywenderlich.com/45152/sprite-kit-tutorial -анимации и текстуры-атласы – DogCoffee

+1

@Smick Спасибо. Я нашел там ответ. –

ответ

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

Это решило мою проблему.

+0

Это тоже помогло. runAction() заставил приложение сбой с EXE_BAD_ACCESS перед тем, как я предварительно загрузил текстуры. Благодаря! – Brainware

+0

У меня возникла проблема с 'repeatActionForever:', которая вызвала сбой, и это исправило это. – Alexander

 Смежные вопросы

  • Нет связанных вопросов^_^