2

I try to add a Emmiter node when I touch on the Screen and remove it (fade it out) when i release my finger. But I want the first node to stay on the screen. What am I doing wrong?

NSMutableArray *childs = [NSMutableArray arrayWithArray:self.children];
[childs removeObjectAtIndex:0];

for (SKEmitterNode *node in childs) {
    [node runAction:[SKAction sequence:@[ [SKAction fadeOutWithDuration:1], [SKAction waitForDuration:3], /*[SKAction removeFromParent]*/ ]]];
}

He only runs the first action not. the other bothes work. But the fade out works when I try it with my first node:

[self.children[0] runAction:[SKAction fadeOutWithDuration:1]];
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
Sam
  • 819
  • 2
  • 7
  • 17

1 Answers1

1

You need to explicitly check whether each node in the array is an instance of the SKEmitterNode class.

for (SKEmitterNode *node in childs) {

    if ([node isKindOfClass:[SKEmitterNode class]])
    {
        [node runAction:[SKAction sequence:@[ [SKAction fadeOutWithDuration:1], [SKAction waitForDuration:3], [SKAction removeFromParent] ]]];
    }

}
ZeMoon
  • 20,054
  • 5
  • 57
  • 98