Jump to content

Mask for mask


ashenemy
 Share

Recommended Posts

21 hours ago, ivan.popelyshev said:

Learn how to use RenderTexture and then use SpriteMaskFilter with a texture that is combined from to others.

Thanks for your reply
I tried, but I did not succeed, you can tell me where I'm wrong
I give an approximate code

var objectTexture = new PIXI.Texture.fromCanvas(canvas);
var objectSprite = new PIXI.Sprite(objectTexture);

var maskTexture = new PIXI.Texture.fromCanvas(canvas);
var maskSprite =  new PIXI.Sprite(maskTexture);

var maskForMaskTexture = new PIXI.Texture.fromCanvas(canvas);
var maskForMaskSprite =  new PIXI.Sprite(maskForMaskTexture);

baseContainer.addChild(maskForMaskSprite);

var renderMaskTexture = new PIXI.RenderTexture(new PIXI.BaseRenderTexture(maskSprite.width, maskSprite.height));

var renderMaskSprite = new PIXI.Sprite(renderMaskTexture);
renderMaskSprite.filters = [ new PIXI.SpriteMaskFilter(maskForMaskSprite) ] 

app.render(renderMaskSprite, renderMaskTexture);

baseContainer.addChild(renderMaskSprite);

var maskFilters = new PIXI.SpriteMaskFilter(renderMaskSprite);
objectSprite.filters = [maskFilters];

baseContainer.addChild(objectSprite);

 

Link to comment
Share on other sites

Actually, what if we just apply two SpriteMaskFilters to one container?

var container = new PIXI.Container();
var mask1 = new PIXI.Sprite(tex1);
var mask2 = new PIXI.Sprite(tex2);

mask1.renderable = false;
container.addChild(mask1);
mask2.renderable = false;
container.addChild(mask2);

container.filters = [ new PIXI.SpriteMaskFilter(mask1), new SpriteMaskFilter(mask2) ];

Or make a structure of two containers inside each other with these two masks?

Are you sure that "mask of a mask" doesn't mean "apply two masks"?

I'm too lazy right now to debug that renderTexture approach ^_^

Link to comment
Share on other sites

10 minutes ago, ivan.popelyshev said:

Actually, what if we just apply two SpriteMaskFilters to one container?


var container = new PIXI.Container();
var mask1 = new PIXI.Sprite(tex1);
var mask2 = new PIXI.Sprite(tex2);

mask1.renderable = false;
container.addChild(mask1);
mask2.renderable = false;
container.addChild(mask2);

container.filters = [ new PIXI.SpriteMaskFilter(mask1), new SpriteMaskFilter(mask2) ];

Or make a structure of two containers inside each other with these two masks?

Are you sure that "mask of a mask" doesn't mean "apply two masks"?

I'm too lazy right now to debug that renderTexture approach ^_^

thanks for the answer
first need to apply the mask to the mask itself, then what happened, apply to the sprite

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...