Mask
Introduction¶
Apply mask on game object. Built-in render of phaser.
- Author: Richard Davey
Usage¶
Add mask¶
- Create mask object
- Create alpha mask from texture
- Create mask from graphics, masked pixel fully visible or fully invisible without changing its alpha (opacity).
- Create graphics
var shape = scene.make.graphics();
- Create mask
or
var mask = shape.createGeometryMask();
var mask = new Phaser.Display.Masks.GeometryMask(scene, shape);
- Create graphics
- Add mask object to image game object
A mask object could be added to many game objects.
// var image = scene.add.image(...); image.setMask(mask); // image.mask = mask;
Error
Don't put game object and its mask into a container together. See this testing, enable line 22-24.
Note
Bitmap Mask is WebGL only.
Note
Can combine Geometry Masks and Blend Modes on the same Game Object, but Bitmap Masks can't.
Clear mask¶
- Clear mask
image.clearMask();
- Clear mask and destroy mask object
image.clearMask(true);
Invert alpha¶
Only GeometryMask has inverse alpha
feature.
- Inverse alpha
mask.setInvertAlpha(); // mask.invertAlpha = true;
- Disable
mask.setInvertAlpha(false); // mask.invertAlpha = false;