/
equals.js
71 lines (54 loc) · 1.66 KB
/
equals.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class Example extends Phaser.Scene
{
create ()
{
const graphics = this.add.graphics({ lineStyle: { width: 5, color: 0xaa00aa } });
const lines = [];
for (let x = 0; x < 8; x++)
{
for (let y = 0; y < 6; y++)
{
const line = new Phaser.Geom.Line(x * 100 + 10, y * 100 + 50, x * 100 + 90, y * 100 + 50);
Phaser.Geom.Line.Rotate(line, Phaser.Math.Between(0, 3) * (Math.PI / 4));
lines.push(line);
}
}
const mouseLine = new Phaser.Geom.Line(-80, 0, 0, 0);
this.input.on('pointermove', pointer =>
{
// round position to (100 * n + 50) pixels
const x = Math.floor(pointer.x / 100) * 100 + 50;
const y = Math.floor(pointer.y / 100) * 100 + 50;
Phaser.Geom.Line.CenterOn(mouseLine, x, y);
redraw();
});
redraw();
function redraw ()
{
graphics.clear();
let strokeRed = false;
for (let i = 0; i < lines.length; i++)
{
graphics.strokeLineShape(lines[i]);
strokeRed = strokeRed || Phaser.Geom.Line.Equals(mouseLine, lines[i]);
}
if (strokeRed)
{
graphics.lineStyle(5, 0xaa0000);
}
else
{
graphics.lineStyle(5, 0xaa00aa);
}
graphics.strokeLineShape(mouseLine);
}
}
}
const config = {
width: 800,
height: 600,
type: Phaser.AUTO,
parent: 'phaser-example',
scene: Example
};
const game = new Phaser.Game(config);