ColorMatrix Hue Shift
Apply a ColorMatrix filter to a sprite and use a tween to cycle through its hue values, creating a shifting color effect.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('egg', 'assets/sprites/bombstar.png');
}
create ()
{
this.add.sprite(200, 300, 'egg');
const bomb = this.add.sprite(600, 300, 'egg');
const fx = bomb.enableFilters().filters.internal.addColorMatrix().colorMatrix;
const tween = this.tweens.addCounter({
from: 0,
to: 360,
duration: 3000,
loop: -1,
onUpdate: () => {
fx.hue(tween.getValue());
}
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#2d2d66',
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);