applying masks to SKEmitterNodes

583 Views Asked by At

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

0

There are 0 best solutions below