Jump to content

Can TilingSprite be used as a mask?


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;

// 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);

// Mask main container
stage.mask = maskTop;

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.


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.

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.


  • Recently Browsing   0 members

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