Rectangle Get Size
Demonstrates how to use Phaser.Geom.Rectangle.GetSize to retrieve the width and height of a rectangle as a Point object.
800 × 600
class Example extends Phaser.Scene
{
create ()
{
const graphics = this.add.graphics({ lineStyle: { width: 2, color: 0x0000aa }, fillStyle: { color: 0x00aa00 } });
const rect = new Phaser.Geom.Rectangle(0, 0, 100, 100);
this.input.on('pointermove', pointer =>
{
rect.width = Phaser.Math.FloorTo(pointer.x, 1, 20);
rect.height = Phaser.Math.FloorTo(pointer.y, 1, 20);
redraw();
});
redraw();
function redraw ()
{
graphics.clear();
graphics.strokeRectShape(rect);
graphics.fillPointShape(Phaser.Geom.Rectangle.GetSize(rect), 10);
}
}
}
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);