2

May be some one can give me a hand… I’m trying to add a couple of SKEmitterNodes in their own SKCropNodes.

My code:

    // left emitter node
    NSString *path = [[NSBundle mainBundle] pathForResource:@"LeftParticle" ofType:@"sks"];
    SKEmitterNode *lEmitterNode = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

    // left crop node
    SKSpriteNode *lMask = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(self.size.width/2, self.size.height)];
    [lMask setAnchorPoint:CGPointZero];
    SKCropNode *lCropNode = [SKCropNode node];
    lCropNode.maskNode = lMask;

    // move the left emitter under the mask
    lEmitterNode.position = CGPointMake(CGRectGetMinX(lMask.frame) + lMask.size.width / 2, self.size.height);

    [lCropNode addChild:lEmitterNode];
    [self addChild:lCropNode];



    // right emitter node
    path = [[NSBundle mainBundle] pathForResource:@"RightParticle" ofType:@"sks"];
    SKEmitterNode *rEmitterNode = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

    // right crop node
    SKSpriteNode *rMask = [SKSpriteNode spriteNodeWithColor:[UIColor greenColor] size:CGSizeMake(self.size.width/2, self.size.height)];
    [rMask setAnchorPoint:CGPointZero];
    rMask.position = CGPointMake(rMask.size.width, 0);
    SKCropNode *rCropNode = [SKCropNode node];
    rCropNode.maskNode = rMask;

    // move the right emitter under the mask
    rEmitterNode.position = CGPointMake(CGRectGetMinX(rMask.frame) + rMask.size.width / 2, self.size.height);

    [rCropNode addChild:rEmitterNode];
    [self addChild:rCropNode];

And this is the result:

enter image description here

As you can see, my red particles render under the left mask... Why?

I’ve tried to reduce the size of mask with:

    lMask.xScale = lMask.yScale = 0.9;
    rMask.xScale = rMask.yScale = 0.9;

And this is the result:

enter image description here

I presume it’s a problem with render buffer, or may be it’s something about zPosition, or a bug, or may be I’m really lost.

Thnx

Albert Perez
  • 121
  • 5
  • I created a blank SpriteKit project and pasted your code in the `initWithSize:` method. Then I added two "bokeh" particle files. For me, everything works fine. The particles are only visible inside the `SKCropNode`. –  Apr 05 '14 at 09:56
  • 1
    Ok, I've changed my particles sks by the default bokeh file... And you are right, it works fine. But if you change the birthrate to value under 30... SURPRISE! the problem appears again. WTF?? – Albert Perez Apr 05 '14 at 16:51
  • Yep, I can confirm that, but the birthrate value "threshold" is not always 30 for me. Seems to be a `SKCropNode` bug. Try changing the `zPosition` of your CropNodes and see what happens. Different values lead to different "overlaps" and "empty patches". Really strange… –  Apr 05 '14 at 18:01

0 Answers0