Sprite Pointer Events
Demonstrates how to change a sprite's texture frame when the mouse pointer enters and leaves its interactive area.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.spritesheet('aliens', 'assets/sprites/bsquadron-enemies.png', { frameWidth: 192, frameHeight: 160 });
}
create ()
{
const alien = this.add.sprite(400, 300, 'aliens', 0).setInteractive();
alien.on('pointerover', function ()
{
this.setFrame(3);
});
alien.on('pointerout', function ()
{
this.setFrame(0);
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);