SKShapeNode with emitter crashes using SKAction removeFromParent

I have an SKShapeNode with a child SKEmitterNode. I have attached the SKAction sequence where the last action is removeFromParent. node behaves correctly without a radiator, doing this action, and then removing itself. However, if the emitter is connected, the entire program crashes (execution proceeds to the main method and appears to hang) when removing shaping.

-(void)fireLasers
{
    SKShapeNode* laser1 = [[SKShapeNode alloc] init];
    //laser1 configuration removed for brevity

    NSString *laserParticlePath = [[NSBundle mainBundle] pathForResource:@"LaserParticle" ofType:@"sks"];
    SKEmitterNode *laserFire = [NSKeyedUnarchiver unarchiveObjectWithFile:laserParticlePath];
    [laser1 addChild:laserFire];

    SKAction* s1 = [SKAction moveByX:0 y:1000 duration:1.0];
    SKAction* s2 = [SKAction removeFromParent];

    SKAction* sequence = [SKAction sequence:@[s1, s2]];
    [laser1 runAction:sequence];

    [self.parent addChild:laser1];
}

The program will work in both cases:

  • I do not attach the emitter
  • I do not include the removeFromParent action

I assume this will work if I attach the action to the emitter to remove FromParent (after 9 seconds) before I can remove it, but this seems like a tedious long-term solution.

- , node , removeFromParent node, ?


, LearnCocos2D

, , . LearnCocos2D , , . , LearnCocos2D, :

laserFire.name = @"laserfire";
SKAction* s2 = [SKAction runAction:[SKAction removeFromParent] onChildWithName:@"laserfire"];

, , .

+4
2

, . , . node, :

SKAction* s1 = [SKAction moveByX:0 y:1000 duration:1.0];
SKAction* s2 = [SKAction runBlock:^{
    [laserFire removeFromParent];
}];
SKAction* s3 = [SKAction removeFromParent];

SKAction* sequence = [SKAction sequence:@[s1, s2, s3]];

Apple , . , .

+3

, , . , , , . , SpriteKit , .

+1

All Articles