具有纹理动画的SKEffectNode不起作用

时间:2014-02-22 12:01:06

标签: ios objective-c sprite-kit skaction skeffectnode

试试这个:

  1. 创建SKEffectNode类
  2. 创建一个8帧左右的小动画,将它们放入地图集文件夹
  3. 将此代码添加到类init
  4. INIT CLASS

    -(id)init {
    
      self = [super init];
    
      if (self) {
    
        SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"shield.atlas"];
    
        NSMutableArray *images=[NSMutableArray arrayWithCapacity:8];
        for (int i=1; i<=8; i++) {
          NSString *fileName=[NSString stringWithFormat:@"shield%d.png",i];
          SKTexture *tempTexture=[atlas textureNamed:fileName];
          [images addObject:tempTexture];
        }
    
        NSUInteger numberOfFrames = [images count];
    
        SKAction *animate = [SKAction animateWithTextures:images timePerFrame:1.0f/numberOfFrames resize:YES restore:NO];
        SKAction *forever = [SKAction repeatActionForever:animate];
        [self runAction:forever];
    
      }
    
      return self;
    
    }
    

    将此节点添加到场景中。结果是没有渲染。请注意,我甚至没有启用效果。

    为什么?

1 个答案:

答案 0 :(得分:3)

SKEffectNode不是SKSpriteNode,因此您无法使用SKSpriteNode的方法。您可以做的是创建一个SKSpriteNode属性,该属性利用您的动画并将其添加为SKEffectNode的孩子。