-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
48 lines (48 loc) · 2.24 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
<!DOCTYPE html>
<html>
<head>
<title>Phaser example animation change before killing it</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<script type="text/javascript" src="js/phaser.min.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var game = new Phaser.Game(500, 500, Phaser.AUTO, '', {preload: preload, create: create, update: update});
function preload() {
/**************************************/
/* Preloading the Sprite Sheets */
// Preloading a Sprite Sheet ('key', 'urlBase', width (px), height (px), frames )
game.load.spritesheet('bomber', 'assets/pics/enemy-bomber-1.png', 60, 40, 3);
game.load.spritesheet('bomberExplode', 'assets/pics/enemy-bomber-1-explode.png', 60, 40, 4);
}
function create() {
// Creating the sprite using the Sprite Sheet bomber ( x, y, key (name of the Sprite Sheet) )
player = game.add.sprite(220, 230, 'bomber');
// Adding an animation ( 'key' )
player.animations.add('blink');
// Playing an animation ( 'key', frameRate, loop )
player.animations.play('blink', 3, true);
// To call the function explodeBomber() when clicking on the game area
game.input.onDown.addOnce(explodeBomber, this);
}
function update() {
// Necessary to make it work !
}
function explodeBomber() {
// To load the new texture (('key', frame))
player.loadTexture('bomberExplode', 0);
// Adding an animation ( 'key' )
player.animations.add('explode');
// To play the animation with the new texture ( 'key', frameRate, loop, killOnComplete)
player.animations.play('explode', 7, false, true);
}
</script>
<h1>Click on the black square to destroy the ship / Cliquez sur le carré noir pour détruire le vaisseau</h1>
</body>
</html>