Jump to content

Can TilingSprite be used as a mask?


ihatetomatoes
 Share

Recommended Posts

Hi there,

completely new to Pixi.js, but so far liking the experience.

I am experimenting with masking and wondering if TilingSprite could be used as a mask for another container?

// Main container
var stage = new PIXI.Container();

// Mask
mask = new PIXI.Container();
var maskUpTile = PIXI.Texture.fromImage('img/mask-up.png');
mask.x = 0;
mask.y = 0;

// Top part of the mask - transparent png
var maskTop = new PIXI.extras.TilingSprite(maskUpTile, renderer.width, renderer.height);
maskTop.x = 0;
maskTop.y = 0;
mask.addChild(maskTop);

// Middle bit - just a black rectangle
var maskMiddle = new PIXI.Graphics();
maskMiddle.beginFill(0x505050, 1);
maskMiddle.drawRect(renderer.width*0.25, renderer.height*0.25, renderer.width/2, renderer.height/2);
maskMiddle.endFill();
mask.addChild(maskMiddle);

// Mask main container
stage.addChild(mask);
stage.mask = maskTop;
renderer.render(stage);

Using the maskMiddle (simple rectangle) as a mask works fine, but I was wondering if repeatable transparent png can be used for masking.

And yes, what am I doing wrong?

Thanks heaps for any tips.

Cheers
Petr

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