2016-02-28 37 views
0

我有一個SKSpriteNode,我試圖在我的touchesbegan中動畫,動畫效果很好,但是當它完成動畫時,我的SKSpriteNode的默認紋理消失了。我的R.atlas包含名爲R1,R2..R7的圖像,我做錯了什麼?非常感謝。爲什麼我的SKSpriteNode中的紋理在動畫完成時被刪除?

@interface MyScene() 
{ 
SKSpriteNode * rightTubeNode; 
} 
@property NSArray* rightTubeAnimationArray; 
@end 

@implementation MyScene 
-(id)initWithSize:(CGSize)size { 
    if (self = [super initWithSize:size]) { 
     SKTextureAtlas *rightTubeAtlas = [SKTextureAtlas atlasNamed:@"R"]; 
     rightTubeTexture = [rightTubeAtlas textureNamed:@"R1"]; 
     NSMutableArray *rightAnimFrames = [NSMutableArray array]; 
     for (int i = 1; i <= rightTubeAtlas.textureNames.count; ++i){ 
      NSString *texture =[NSString stringWithFormat:@"R%d",i]; 
      [rightAnimFrames addObject:[rightTubeAtlas textureNamed:texture]]; 
      } 
     self.rightTubeAnimationArray = rightAnimFrames; 
     rightTubeNode = [self createRightTubeNode]; 
     rightTubeNode.position = CGPointMake(self.frame.size.width/2+rightTubeNode.frame.size.width/2,50); 
     rightTubeNode.zPosition = 0.1; 
     [self addChild:rightTubeNode]; 
    } 
    return self; 
} 
- (SKSpriteNode *)createRightTubeNode 
{ 
    SKSpriteNode *rightTube = [SKSpriteNode spriteNodeWithTexture:rightTubeTexture]; 
    rightTube = [SKSpriteNode spriteNodeWithTexture:rightTubeTexture]; 
    rightTube.name = @"rightTubeNode"; 
    return rightTube; 
} 
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
     for (UITouch *touch in touches) { 
      CGPoint location = [touch locationInNode:self]; 
      CGPoint nodesLocation = CGPointMake(location.x,self.frame.size.height/2); 

      if (nodesLocation.x>self.frame.size.width/2) { 
       SKNode *archerNode = [self childNodeWithName:@"rightTubeNode"]; 
       if (archerNode != nil){ 
       SKAction *animate = [SKAction animateWithTextures:self.rightTubeAnimationArray 
              timePerFrame: 0.02]; 
       [archerNode runAction:animate]; 
       } 
      } 
     } 
    } 
+1

你所說的「水漲船高」的意思是?動畫完成後,節點的紋理將爲R7。你看到了什麼紋理? – Whirlwind

+0

我在白色背景上看到了十字架,當圖像變暗時,它不會顯示R1.png(這是R.atlas中的第一個圖像,也是動畫的第一幀)。它顯示了一個紅十字。 @Whirlwind –

+1

缺少資源,好吧。首先,檢查你的紋理名稱,第二,清除模擬器的內容和設置(模擬器 - >重置內容和設置),然後重試。另外你如何創建你的地圖集(使用.atlas文件夾或資產目錄)? – Whirlwind

回答

0

重新添加R.atlas(與檢查創建組選項框)沒有任何進一步改變的伎倆,由於@Whirlwind

相關問題