Vignette Sprite
Demonstrates how to apply a vignette post-processing filter to an individual sprite and toggle the effect on and off.
800 × 600
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('pic', 'assets/pics/robot-ai.jpg');
}
create ()
{
const sprite = this.add.image(400, 300, 'pic');
const fx = sprite.enableFilters().filters.internal.addVignette();
this.add.text(10, 10, 'Click to toggle vignette on/off').setResolution(window.devicePixelRatio);
this.input.on('pointerdown', () => {
fx.active = !fx.active;
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#0a0067',
parent: 'game-container',
scene: Example
};
let game = new Phaser.Game(config);