Skip to content

Commit 04fdcb3

Browse files
committed
fixes from Sole notes
1 parent bfe11e4 commit 04fdcb3

File tree

7 files changed

+66
-59
lines changed

7 files changed

+66
-59
lines changed

README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ git clone https://github.com/firefoxos-gamedev/mortar-phaser-game-stub.git
1818
Or download the latest version in this [ZIP file](https://github.com/firefoxos-gamedev/mortar-phaser-game-stub/archive/master.zip).
1919

2020

21-
## Usage
22-
23-
Start a local server to simulate accessing the hosted app from the browser, and trying the *Install* button flow.
24-
25-
For example:
26-
27-
````bash
28-
python -m SimpleHTTPServer 8000
29-
````
30-
31-
then access `localhost:8000` or `your.computer.ip:8000` (for example, `192.168.0.25`) using Firefox (Desktop or Mobile), or the Browser app in a Firefox OS simulator (or device).
32-
33-
You'll need to use the IP address when using a physical device. Change the port accordingly, if you're running a webserver in this port already.
34-
3521
## Phaser Framework
3622

3723
[Phaser](http://phaser.io) is a proven open source framework for creating HTML5 games. It has many features such as input control, game loops, camera control, tilemaps and more all baked in. Its a great tool to help you create your game and not focus on trivia stuff that is not related to your project or vision.
@@ -46,7 +32,7 @@ $ bower update
4632
## Code walkthrough
4733
The code is contained in three files &mdash boot.js, preloader.js, game.js &mdash each serves a different purpose and is explained below:
4834

49-
### boot.js
35+
### main.js
5036
This file register our listener for the *DOMContentLoaded* event. This event will fire once all the html/css/js files are loaded.
5137

5238
In this file we setup the Phaser framework and register our game states. A game can have multiple game states. This stub has two states each defined in their own file.

index.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<meta charset="UTF-8" />
5-
<title>Phaser Game Stub</title>
6-
<link rel="stylesheet" href="css/style.css" type="text/css" />
7-
<script src="js/phaser/phaser.js"></script>
8-
<script src="js/game/boot.js"></script>
9-
<script src="js/game/preloader.js"></script>
10-
<script src="js/game/game.js"></script>
11-
</head>
12-
<body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Phaser Game Stub</title>
6+
<link rel="stylesheet" href="css/style.css" type="text/css" />
7+
<script defer src="js/phaser/phaser.js"></script>
8+
<script defer src="js/game/preloader.js"></script>
9+
<script defer src="js/game/game.js"></script>
10+
<script defer src="js/game/main.js"></script>
11+
</head>
12+
<body>
1313

14-
<div id="game"></div>
14+
<div id="game"></div>
1515

16-
</body>
16+
</body>
1717
</html>

js/game/boot.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

js/game/game.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BasicGame.Game = function(game) {};
1+
GameStates.Game = function(game) {};
22

33
/**
44
* This is the Game game state. Its our game loop responsible for the game itself.
@@ -10,7 +10,7 @@ BasicGame.Game = function(game) {};
1010
* Refer to: http://docs.phaser.io/Phaser.State.html
1111
*/
1212

13-
BasicGame.Game.prototype = {
13+
GameStates.Game.prototype = {
1414
create: function() {
1515

1616
// Add the background
@@ -28,8 +28,8 @@ BasicGame.Game.prototype = {
2828

2929
update: function() {
3030
/*
31-
This function is called in a loop using requestAnimationFrame(). It is our game loop, our heartbeat. Every time
32-
it is called we process the user input and update the display.
31+
This function is called in a loop using requestAnimationFrame(). It is our game loop, our heartbeat.
32+
Every time it is called we process the user input and update the display.
3333
*/
3434

3535

js/game/main.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
document.addEventListener("DOMContentLoaded", function(event) {
3+
4+
// Create your Phaser game and inject it into the game div.
5+
6+
// Game world will fill the whole viewport. If this is not the desired outcome then change those values.
7+
var width = window.innerWidth;
8+
var height = window.innerHeight;
9+
10+
// Phaser.AUTO constant below means it will automatically switch between WebGL or Canvas depending on the platform.
11+
// Check out docs.phaser.io/Phaser.Game.html
12+
var game = new Phaser.Game(width, height, Phaser.AUTO, "game");
13+
14+
/*
15+
Add the States the game has.
16+
17+
A game can have multiple states. States have a lifecycle. You use states to create your own game.
18+
They provides quick access to common functions such as the camera, cache, input, match, sound and more.
19+
20+
You can use multiple states to better organize your code. In this template we use two states one to load our
21+
assets and one for the gameloop. We could have done all that in a single state but that could lead to larger files
22+
that are harder to maintain.
23+
24+
more info about states at: docs.phaser.io/Phaser.State.html
25+
*/
26+
game.state.add('Preloader', GameStates.Preloader); // <-- Loads the assets
27+
game.state.add('Game', GameStates.Game); // <-- Game loop.
28+
29+
// Now start the preloader state.
30+
game.state.start('Preloader');
31+
32+
});

js/game/preloader.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
var BasicGame = {}; // <-- Object to hold all our game states.
1+
/**
2+
* below we declare GameStates which is an empty object that will contain our game states.
3+
* We're using this to avoid having multiple globals around.
4+
*/
5+
6+
var GameStates = {};
27

38
/**
49
* This is the Preloader game state. It is the first to run. It loads all the assets used by the game.
510
*/
611

7-
BasicGame.Preloader = function (game) {
12+
GameStates.Preloader = function (game) {
813
// placeholder, you can set some game state options in here if needed.
914
// Refer to: http://docs.phaser.io/Phaser.State.html
1015
};
1116

12-
BasicGame.Preloader.prototype = {
17+
GameStates.Preloader.prototype = {
1318

1419
/*
1520
Game states have many functions that will be called at different stages of its lifecycle.
@@ -20,11 +25,15 @@ BasicGame.Preloader.prototype = {
2025
In this case here:
2126
- preload(): will be called to load our game assets. Once loaded they are cached and any
2227
other game state may use them.
23-
- update(): this is the gameloop function. I will be called using requestAnimationFrame() in a loop
28+
- update(): this is the game loop function. It will be called using requestAnimationFrame() in a loop
2429
until we do something to exit. In this case we switch to the Game state.
2530
*/
2631

2732
preload: function() {
33+
34+
// The images below are just placeholders to show how to load assets.
35+
// Replace them with your own.
36+
2837
this.load.image('background', 'assets/background.png');
2938
this.load.image('player', 'assets/player.png');
3039
},

manifest.webapp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
"name": "Phaser Game Stub",
44
"description": "A game app template",
55
"launch_path": "/index.html",
6-
"icons": {
7-
"16": "/img/icons/mortar-16.png",
8-
"48": "/img/icons/mortar-48.png",
9-
"128": "/img/icons/mortar-128.png"
10-
},
116
"developer": {
127
"name": "Your Name",
138
"url": "http://example.com"
@@ -17,6 +12,10 @@
1712
"es": {
1813
"name": "Plantilla de juego",
1914
"description": "Plantilla para apps de juegos"
15+
},
16+
"pt": {
17+
"name": "Template de jogo",
18+
"description": "Um template para criação de jogos"
2019
}
2120
},
2221
"default_locale": "en"

0 commit comments

Comments
 (0)