Sign in to follow this  

Building a mask from multiple sprites

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:



The hole sprite:



Some psuedo code:

//full blimp mask

this.mask = new PIXI.Sprite(blimpMask);
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');

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:




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?

Share this post

Link to post
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: ,  use layer "getRenderTexture()" method to get temporary screen-size render texture for your blimp:

Share this post

Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.