Paint with Render Texture
Demonstrates how to create a simple drawing effect by drawing a brush sprite onto a Render Texture as the pointer moves.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('brush', 'assets/sprites/brush1.png');
}
create ()
{
const rt = this.add.renderTexture(400, 300, 800, 600);
this.input.on('pointermove', pointer =>
{
if (pointer.isDown)
{
rt.draw('brush', pointer.x - 32, pointer.y - 32).render();
}
}, this);
}
}
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);