-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (69 loc) · 2.36 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>hello phaser!</title>
<script src="phaser.min.js"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function() {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
var cursors;
function preload () {
game.load.image('ball', 'assets/ball.png');
game.load.spritesheet('star', 'assets/starsheet.png', 26, 24, 8);
}
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
cursors = game.input.keyboard.createCursorKeys();
ball = game.add.sprite(400, 400, 'ball');
game.physics.enable(ball, Phaser.Physics.ARCADE);
ball.body.velocity.y = 100;
ball.body.collideWorldBounds = true;
ball.body.bounce.set(1);
ball.body.gravity.set(0, 900);
/// Star Spritesheet
star = game.add.sprite(600, 500, 'star');
star.animations.add('rotate');
star.animations.play('rotate', 10, true);
game.physics.enable(star, Phaser.Physics.ARCADE);
/// Collision Effect
emitter = game.add.emitter(0, 0, 100);
emitter.makeParticles('star');
emitter.setScale(0.1, 1, 0.1, 1, 6000, Phaser.Easing.Quintic.Out);
emitter.gravity = 200;
}
function update() {
game.physics.arcade.collide(ball, star, collisionHandler, null, this);
if (cursors.left.isDown)
{
ball.body.velocity.x = -300;
}
else if (cursors.right.isDown)
{
ball.body.velocity.x = 300;
}
else
{
ball.body.velocity.x = 0;
}
}
function collisionHandler (obj1, obj2) {
//game.stage.backgroundColor = '#992d2d';
emitter.x = star.body.x;
emitter.y = star.body.y;
// The first parameter sets the effect to "explode" which means all particles are emitted at once
// The second gives each particle a 2000ms lifespan
// The third is ignored when using burst/explode mode
// The final parameter (10) is how many particles will be emitted in this single burst
emitter.start(true, 2000, null, 10);
}
function render() {
//debug helper
game.debug.spriteInfo(ball, 32, 32);
}
};
</script>
</body>
</html>