|
3 | 3 | // Parameters: width of the game, height of the game, how to render the game, the name of the div in the html that will contain the game |
4 | 4 | var game = new Phaser.Game(500, 600, Phaser.AUTO, 'game_div'); |
5 | 5 |
|
6 | | -// An array to store the different states of our game (play, menu, credits, etc.) |
| 6 | +// An array to store the different states of our game. A state is a specific scene of a game like a menu, a game over screen, etc. |
7 | 7 | var game_state = {}; |
8 | 8 |
|
9 | | -// Let's define our first state: play |
10 | | -game_state.play = function(game) { }; |
11 | | -game_state.play.prototype = { |
| 9 | +// Let's define our first state. I'll call it 'main' since we only have one. |
| 10 | +game_state.main = function(game) { }; |
| 11 | +game_state.main.prototype = { |
12 | 12 |
|
13 | 13 | preload: function() { |
14 | | - // Everything in this function will be executed at the beginning. That’s where we usually load the game’s assets (images, sounds, etc.) |
15 | | - |
| 14 | + // Everything in this function will be executed at the beginning. That’s where we usually load the |
| 15 | + |
16 | 16 | // Load a sprite in the game |
17 | 17 | // Parameters: name of the image, path to the image |
18 | 18 | game.load.image('hello', 'assets/hello.png'); |
19 | 19 | }, |
20 | 20 |
|
21 | 21 | create: function() { |
22 | | - // This function will be called after the preload function. Here we set up the game: place sprites, add labels, etc. |
| 22 | + // This function will be called after the preload function. Here we set up the game, display sprites, add labels, etc. |
23 | 23 |
|
24 | 24 | // Display a sprite on the screen |
25 | 25 | // Parameters: x position, y position, name of the sprite |
26 | 26 | hello_sprite = game.add.sprite(250, 300, 'hello'); |
27 | 27 | }, |
28 | 28 |
|
29 | 29 | update: function() { |
30 | | - // This is where you will spend the most of your time. This function is called 60 times per seconds to update the state of your game. |
| 30 | + // This is where we will spend the most of our time. This function is called 60 times per second to update the game. |
31 | 31 |
|
32 | 32 | // Increase the angle of the sprite by one |
33 | 33 | hello_sprite.angle += 1; |
34 | 34 | } |
35 | 35 | } |
36 | 36 |
|
37 | | -// And we tell Phaser to add and start our play state |
38 | | -game.state.add('play', game_state.play); |
39 | | -game.state.start('play'); |
| 37 | +// And finally we tell Phaser to add and start our 'main' state |
| 38 | +game.state.add('main', game_state.main); |
| 39 | +game.state.start('main'); |
0 commit comments