/
shake.js
44 lines (37 loc) · 1.04 KB
/
shake.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
{
constructor ()
{
super();
}
preload ()
{
this.load.image('pic', 'assets/pics/a-new-link-to-the-past-by-ptimm.jpg');
this.load.image('logo', 'assets/sprites/phaser3-logo.png');
}
create ()
{
this.add.image(400, 300, 'pic');
const logo = this.add.image(400, 200, 'logo')
.setVisible(false);
// Let's show the logo when the camera shakes, and hide it when it completes
this.cameras.main.on('camerashakestart', function () {
logo.setVisible(true);
});
this.cameras.main.on('camerashakecomplete', function () {
logo.setVisible(false);
});
// Every time you click, shake the camera
this.input.on('pointerdown', function () {
this.cameras.main.shake(500);
}, this);
}
}
const config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);