Rectangle Area
Calculate the area of a Rectangle based on pointer movement and use the result to resize a secondary square.
800 × 600
class Example extends Phaser.Scene
{
create ()
{
const graphics = this.add.graphics({ lineStyle: { width: 2, color: 0xaa0000 }, fillStyle: { color: 0x0000aa } });
const rect = new Phaser.Geom.Rectangle();
const square = new Phaser.Geom.Rectangle();
this.input.on('pointermove', pointer =>
{
graphics.clear();
rect.width = pointer.x;
rect.height = pointer.y;
const area = Phaser.Geom.Rectangle.Area(rect);
square.width = square.height = Math.sqrt(area);
graphics.fillRectShape(square);
graphics.strokeRectShape(rect);
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
width: 800,
height: 600,
type: Phaser.AUTO,
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);