This class, a subclass of Sprite, allows you to clip the Sprite's content in a rectangular area. The mask is always given in stage coordinates and cannot be rotated.
Beware that the clipping rectangle does not affect the bounds of the sprite, i.e. the “width” and “height” properties won't reflect the clipping area. Touches outside the clipping rectangle are ignored, though.
To use the mask, assign a value to the “clipRect” property:
var sprite:ClippedSprite = new ClippedSprite(); addChild(sprite); // the sprite works like you're used to sprite.addChild(anObject); sprite.addChild(anotherObject); // set the mask rectangle in stage coordinates sprite.clipRect = new Rectangle(10, 10, 380, 280);
Note: Resistcorp created a version of this extension that allows nested clipping regions. Find it here!
hitTest()
methodmClipRect
to be null in hitTest()
method%gist(2422317)%
I believe this is now a default part of the Starling framework.