|
1 |
| -var config = { |
2 |
| - type: Phaser.WEBGL, |
3 |
| - parent: 'phaser-example', |
4 |
| - scene: { |
5 |
| - preload: preload, |
6 |
| - create: create |
7 |
| - } |
8 |
| -}; |
9 |
| - |
10 |
| -var game = new Phaser.Game(config); |
11 |
| - |
12 |
| -function preload () |
| 1 | +class Example extends Phaser.Scene |
13 | 2 | {
|
14 |
| - this.load.image('eye', 'assets/pics/lance-overdose-loader-eye.png'); |
15 |
| -} |
16 |
| - |
17 |
| -function create () |
18 |
| -{ |
19 |
| - var image = this.add.sprite(200, 300, 'eye').setInteractive(); |
20 |
| - |
21 |
| - this.input.setDraggable(image); |
22 |
| - |
23 |
| - // The pointer has to move 16 pixels before it's considered as a drag |
24 |
| - this.input.dragDistanceThreshold = 16; |
| 3 | + constructor() |
| 4 | + { |
| 5 | + super(); |
| 6 | + } |
25 | 7 |
|
26 |
| - this.input.on('dragstart', function (pointer, gameObject) { |
| 8 | + preload () |
| 9 | + { |
| 10 | + this.load.image('bg', 'assets/skies/cavern1.png'); |
| 11 | + this.load.image('goblin', 'assets/pics/goblin.png'); |
| 12 | + this.load.image('spider', 'assets/pics/spider.png'); |
| 13 | + } |
27 | 14 |
|
28 |
| - gameObject.setTint(0xff0000); |
| 15 | + create () |
| 16 | + { |
| 17 | + this.add.image(400, 300, 'bg'); |
| 18 | + this.add.text(16, 16, 'Move 32px before drag starts').setFontSize(24).setShadow(1, 1); |
29 | 19 |
|
30 |
| - }); |
| 20 | + this.add.image(200, 300, 'goblin').setInteractive({ draggable: true }); |
| 21 | + this.add.image(600, 300, 'spider').setInteractive({ draggable: true }); |
31 | 22 |
|
32 |
| - this.input.on('drag', function (pointer, gameObject, dragX, dragY) { |
| 23 | + // The pointer has to move 32 pixels before it's considered as a drag |
| 24 | + this.input.dragDistanceThreshold = 32; |
33 | 25 |
|
34 |
| - gameObject.x = dragX; |
35 |
| - gameObject.y = dragY; |
| 26 | + this.input.on('drag', (pointer, gameObject, dragX, dragY) => { |
36 | 27 |
|
37 |
| - }); |
| 28 | + gameObject.setPosition(dragX, dragY); |
38 | 29 |
|
39 |
| - this.input.on('dragend', function (pointer, gameObject) { |
| 30 | + }); |
| 31 | + } |
| 32 | +} |
40 | 33 |
|
41 |
| - gameObject.clearTint(); |
| 34 | +const config = { |
| 35 | + type: Phaser.AUTO, |
| 36 | + width: 800, |
| 37 | + height: 600, |
| 38 | + parent: 'phaser-example', |
| 39 | + scene: Example |
| 40 | +}; |
42 | 41 |
|
43 |
| - }); |
44 |
| -} |
| 42 | +const game = new Phaser.Game(config); |
0 commit comments