forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbody test.js
More file actions
77 lines (52 loc) · 1.56 KB
/
Copy pathbody test.js
File metadata and controls
77 lines (52 loc) · 1.56 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
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('coke', 'assets/sprites/cokecan.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
var group;
var group2;
var atari;
var coke;
var dropper;
function create() {
// make our world wider
game.world.setBounds(0, 0, 2000, 600);
// shift the camera (still works)
// game.camera.x = 400;
game.world.angle = 10;
// base group
group = game.add.group();
// group.angle = 10;
group.y = 200;
atari = group.create(0, 0, 'atari1');
coke = group.create(340, 0, 'coke');
// dropper group
group2 = game.add.group();
dropper = group2.create(400, 0, 'mushroom');
dropper.inputEnabled = true;
dropper.input.enableDrag();
dropper.events.onDragStop.add(checkDrop, this);
group2.y = 400;
}
function checkDrop() {
if (Phaser.Rectangle.intersects(dropper.body, atari.body))
{
atari.alpha = 0.3;
}
else if (Phaser.Rectangle.intersects(dropper.body, coke.body))
{
coke.alpha = 0.3;
}
}
function update() {
group.x += 0.5;
}
function render() {
game.debug.renderWorldTransformInfo(dropper, 32, 32);
game.debug.renderText(dropper.position.x, 200, 32);
game.debug.renderText(dropper.position.y, 260, 32);
game.debug.renderRectangle(atari.body, 'rgba(255,0,0,0.3)');
game.debug.renderRectangle(coke.body, 'rgba(255,0,0,0.3)');
game.debug.renderRectangle(dropper.body, 'rgba(0,255,0,0.3)');
}