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];
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"];
, , .