Pixelate Sprite Filter
Demonstrates how to apply a pixelation effect to a single Sprite and toggle its active state.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('pic', 'assets/pics/neotokyo-ai.jpg');
}
create ()
{
const sprite = this.add.image(400, 300, 'pic');
const fx = sprite.enableFilters().filters.internal.addPixelate(2);
const text = this.add.text(10, 10, 'Click to toggle FX.Pixelate on/off').setResolution(window.devicePixelRatio);
text.setShadow(2, 2);
this.input.on('pointerdown', () => {
fx.active = !fx.active;
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#000000',
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);