TileSprite Input Interaction
Demonstrates how to make a TileSprite interactive and handle pointer events, such as changing its tint and position when clicked.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
create ()
{
const image = this.add.tileSprite(200, 100, 512, 256, 'mushroom');
image.setInteractive();
image.setAngle(20);
image.setOrigin(0);
image.on('pointerdown', function ()
{
this.setTint(Math.random() * 16000000);
// So something happens for canvas
this.x += 2;
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);