This project is a starter for a Phaser JS project that includes automatic asset loading, an ExpressJS server for serving local assets needed for the game, and an example mocha test for unit tests.
To run this project, a minified version of Phaser CE needs to be added to the
src/static/lib directory. This can be found in the releases of Phaser CE's GitHub repository.
After that, the following commands will assist in running the project.
# install node modules listed in package json npm install # run the server # while this is running, game will be available at localhost:3000 npm start # run mocha tests npm test
General File Structure
The main game files for Phaser are in
src/static/js/game/states. These are partial files that, when put together in order (see the
AssetLoader provided in
src/static/js/loaders, used to load static assets into the game (called in
preload function of
While the app is running with
npm start, all files within
src/static/js/build.min.js. The files to be included are listed in
config.json -- included in the repository for better visibility into how things work -- under the key
jsFiles. This is done to preserve the order needed for the partial game files (mentioned earlier in the
General File Structure section).
npm run build -- --skip-minify (mind the extra double dashes).
The boot state is in
src/static/js/game/states/boot.js, and it's in charge of loading any initial assets (in this example, the json that defines all the other static assets the game needs, like images, audio, and texture atlases with their corresponding json). The primary state of the game is in
src/static/js/game/states/play.js which contains the main start function and the state's update and render loops. Should your game require other states, they can be created and added in a similar fashion to these states.
To add assets that the
AssetLoader will pick up, their paths can be added to
static/json/assets.json. For more information on what can be added, see the comments and code in
AssetLoader itself, located in