-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathworld game objects.js
More file actions
116 lines (88 loc) · 3.06 KB
/
world game objects.js
File metadata and controls
116 lines (88 loc) · 3.06 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class Example extends Phaser.Scene
{
controls;
text2;
text;
preload ()
{
this.load.image('eye', 'assets/pics/lance-overdose-loader-eye.png');
}
create ()
{
for (let i = 0; i < 32; i++)
{
const x = Phaser.Math.Between(0, 2000);
const y = Phaser.Math.Between(0, 2000);
this.add.sprite(x, y, 'eye').setInteractive();
}
this.input.on('gameobjectover', (pointer, gameObject) =>
{
gameObject.setTint(0xff0000);
});
this.input.on('gameobjectout', (pointer, gameObject) =>
{
gameObject.clearTint();
});
const cursors = this.input.keyboard.createCursorKeys();
const controlConfig = {
camera: this.cameras.main,
left: cursors.left,
right: cursors.right,
up: cursors.up,
down: cursors.down,
zoomIn: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q),
zoomOut: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E),
acceleration: 0.06,
drag: 0.0005,
maxSpeed: 1.0
};
this.controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig);
// this.cameras.main.setBackgroundColor('rgba(255, 0, 0, 0.5)');
// this.cameras.main.setZoom(0.8);
// this.cameras.main.setRotation(Phaser.Math.DegToRad(10));
this.text = this.add.text(100, 200, 'x: 0 y: 0', { font: '18px Courier', fill: '#00ff00' }).setScrollFactor(0);
this.text2 = this.add.text(100, 400, '', { font: '18px Courier', fill: '#00ff00' }).setScrollFactor(0);
this.input.keyboard.on('keydown-Z', function (event)
{
this.cameras.main.setRotation(this.cameras.main.rotation + 0.01);
}, this);
this.input.keyboard.on('keydown-X', function (event)
{
this.cameras.main.setRotation(this.cameras.main.rotation - 0.01);
}, this);
}
update (time, delta)
{
this.controls.update(delta);
const cam = this.cameras.main;
// Take a coordinate from screen space and convert it into World space within the Camera
// var p = cam.screenToCamera({ x: this.input.x, y: this.input.y });
const p = this.input.activePointer.positionToCamera(cam);
this.text.setText([
`cx: ${cam.scrollX}`,
`cy: ${cam.scrollY}`,
'',
`sx: ${this.input.x}`,
`sy: ${this.input.y}`,
'',
`px: ${p.x}`,
`py: ${p.y}`
]);
this.text2.setText([
`a: ${cam.matrix.matrix[0]}`,
`b: ${cam.matrix.matrix[1]}`,
`c: ${cam.matrix.matrix[2]}`,
`d: ${cam.matrix.matrix[3]}`,
`tx: ${cam.matrix.matrix[4]}`,
`ty: ${cam.matrix.matrix[5]}`
]);
}
}
const config = {
type: Phaser.WEBGL,
width: 800,
height: 600,
parent: 'phaser-example',
scene: Example
};
const game = new Phaser.Game(config);