/
perimeter.js
44 lines (31 loc) · 975 Bytes
/
perimeter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Example extends Phaser.Scene
{
create ()
{
const graphics = this.add.graphics({ lineStyle: { width: 2, color: 0x0000aa } });
const rect = new Phaser.Geom.Rectangle(350, 250, 100, 100);
const text = this.add.text(100, 100, '');
this.input.on('pointermove', pointer =>
{
rect.width = Phaser.Math.FloorTo((pointer.x - 400) * 2, 1, 25);
rect.height = Phaser.Math.FloorTo((pointer.y - 300) * 2, 1, 25);
Phaser.Geom.Rectangle.CenterOn(rect, 400, 300);
text.setText(`Perimeter : ${Phaser.Geom.Rectangle.Perimeter(rect)}`);
redraw();
});
redraw();
function redraw ()
{
graphics.clear();
graphics.strokeRectShape(rect);
}
}
}
const config = {
width: 800,
height: 600,
type: Phaser.AUTO,
parent: 'phaser-example',
scene: Example
};
const game = new Phaser.Game(config);