Geometry Mask From Shape
Demonstrates how to apply a hidden Shape object as a geometry mask for an image and animate the mask's rotation using a tween.
800 × 600
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('pic', 'assets/pics/cougar-dragonsun.png');
}
create ()
{
const pic = this.add.image(400, 300, 'pic');
const maskRect = this.add.rectangle(400, 300, 480, 256, 0x000000).setVisible(false);
pic.enableFilters().filters.external.addMask(maskRect);
this.tweens.add({
targets: maskRect,
angle: 360,
duration: 5000,
repeat: -1
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.WEBGL,
parent: 'game-container',
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);