Fork me on GitHub
View source

package com.haxepunk.masks

class Imagemask


extends Pixelmask

A bitmap mask used for pixel-perfect collision.

Example usage:

class Object extends Entity
{
    public function new()
    {
        super();
        var sprite = new Image("myimage.png", 100, 100);
        graphic = sprite;
        mask = new Imagemask(sprite);
    }
}

Remember to call "mask.update()" when you update the image.

If you are using RenderMode.HARDWARE mode, Imagemask will still work, but only if your Image source is created with a BitmapData. AtlasData is not currently supported.

Constructor

View source

new (source : Image) : Void

Constructor.


Parameters:
source   

The image to use as a mask.

x   

X offset of the mask.

y   

Y offset of the mask.

Functions

View source

getBounds () : Rectangle

Calculates the bound box of the source Image, taking account the Image transformation.


Returns:

the bound box in local coordinates.

View source

setSource (newsource : Image) : Void

Update Source image. Calls update().


Parameters:
newsource   

Update source image.