Generate Texture from Graphics
Demonstrates how to convert a Graphics object into a reusable texture that can be applied to Images or Sprites.
800 × 600
class Example extends Phaser.Scene
{
create ()
{
const graphics = this.make.graphics().fillStyle(0x00ff00).fillRect(0, 0, 800, 100);
graphics.generateTexture('hudbar', 800, 100);
graphics.destroy();
this.add.image(400, 300, 'hudbar');
}
}
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);