-2

尝试这个:

  1. 创建一个 SKEffectNode 类
  2. 制作一个小动画,8帧左右,放入atlas文件夹
  3. 将此代码添加到类初始化

初始化类

-(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;

}

将此节点添加到您的场景中。结果是什么都没有渲染。请注意,我什至还没有启用效果。

为什么?

4

1 回答 1

3

SKEffectNode不是 a SKSpriteNode,所以你不能使用SKSpriteNode's 方法。您可以做的是创建一个SKSpriteNode利用您的动画的属性并将其添加为您的SKEffectNode.

于 2014-02-22T12:37:21.783 回答