Thursday, March 10, 2011

Simple mask

Mask is a layer that covers our appropriate object. It is always problem what is mask and what is masked. And what should be on mask layer. So here is short description with example. Look at this schema:
From the right:
  • back - complete image that is covered
  • mask - objects and shapes here creates holes through which we see image from back
  • result - this is what we get as result of using mask
Background can be everything. In this example it's a simple image:

_background = new _BackGround();
addChild(_background);

Mask can be simple shape. If it's static it don't have to be added as child to stage. But if we want do some action on mask it's neccesary:

var mask:Sprite = new Sprite();
mask.graphics.beginFill(0xFF6600, 1);
mask.graphics.drawRect(-40, -40, 80, 80);
mask.graphics.endFill();
addChild(mask);
_background.mask = mask;
mask.startDrag(true);

In this example mask is a draggable square that follows mouse cursor. Check it!



No comments:

Post a Comment