为什么我的SKSpriteNode中的纹理在完成动画时会被删除?

时间:2016-02-28 21:45:24

标签: ios objective-c sprite-kit

我有一个SKSpriteNode,我试图在我的touchesbegan中设置动画,动画效果很好但是当它完成动画时,我的SKSpriteNode的默认纹理消失了。我的R.atlas包含名为R1,R2..R7的图像,我做错了什么?非常感谢。

@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 个答案:

答案 0 :(得分:0)

重新添加R.atlas(检查创建组选项框)而不做任何进一步的更改就行了,谢谢@Whirlwind