Jump to content

Building a mask from multiple sprites


Saltallica
 Share

Recommended Posts

Is it possible? 

For example - I have a sprite I want to add holes to. In this case, it's a blimp. A player can hit the blimp multiple times. Each time the blimp is hit, a hole should be placed in the spot where the hit occurred.  

The base mask sprite:

image.thumb.png.b5f49033b3d405cf0fb5970ac721b9d1.png

 

The hole sprite:

image.png.d17bea80525800ff024263e8f1538513.png

 

Some psuedo code:

//full blimp mask

this.mask = new PIXI.Sprite(blimpMask);
this.sprite.addChild(this.mask);
this.sprite.mask = this.mask;



//inside my hit testing methods
//add a child sprite to the mask sprite


var localPos = this.sprite.toLocal({x: pos.x, y: pos.y})

var hole = new PIXI.Sprite.fromImage('/img/blimp-hit.png');
							
this.mask.addChild(hole);

hole.position.x = localPos.x;
hole.position.y = localPos.y;
hole.scale.x = 0.5;
hole.scale.y = 0.5;
hole.anchor.x = 0.5;
hole.anchor.y = 0.5;



 

So, if there were two holes added to the mask sprite, they would be added as children of the main mask:

 

image.thumb.png.e8d17ef147b23b87252c93f107a46564.png

 

I would expect the composite sprite, when set as a mask, to have holes as outlined above, but the children sprites are never accounted for when the parent sprite is set as a mask.

Is there a definitive way to make a dynamic mask that is comprised of multiple sprites?

Link to comment
Share on other sites

It is not a newbie material.

Use renderTexture to store composite mask before you render the stage.

The trick you are talking about is possible with pure container/layer manipulation, but you need to study the plugin first: https://github.com/pixijs/pixi-display/blob/layers/bin/pixi-layers.js ,  use layer "getRenderTexture()" method to get temporary screen-size render texture for your blimp: https://pixijs.io/examples/#/layers/lighting.js

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...