Reputation: 6826
I use the following code block and when I debug I see that SKShapeNode's accumulated frame is now {{-160.03586, -42.431793}, {470.03586, 519.50903}}
instead of something like {{0,0}, {100,300}}
.
If I comment out this whole particle code, accumulatedFrame
is meaningful again.
I need it to be meaningful as I use nodesAtPoint
in touchesBegan
. Any nonsense value causes nodesAtPoint
to find irrelevant nodes too as accumulatedFrame is now weird for all and they all intersect...
I use the following code block and I couldn't find out the problem. What do I miss here?
NSString *path = [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"];
SKEmitterNode *particles = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
particles.position = CGPointMake(_selectedNode.frame.size.width/2, _selectedNode.frame.size.height/2);
[particles runAction:[SKAction sequence:@[[SKAction waitForDuration:.2],
[SKAction fadeAlphaTo:0 duration:0.2],
[SKAction removeFromParent]]] completion:^{
[particles removeFromParent];
}];
[_selectedNode addChild:particles];
Upvotes: 0
Views: 232
Reputation: 2576
accumulatedFrame is what it sounds like, it is the minimum rectangle that contains all the graphical objects of your node. An emitternode will actually add nodes to the object it is added to. It works exactly as intended when calculating the accumulated frame.
The way to get around this is to have the emitter node have a "target node". SKEmitterNode has a property called .targetNode. It basically means that it will drop its sprites into that node.
I've found it a good method to have a single SKNode which contains all of my emitted nodes. This is then separate from the layers I click.
Check the SKEmitterNode class reference for more information on the targetNode.
SKEmitter Node class reference
Upvotes: 3