This repo contains a project template for building a multiplatform mobile game with Phaser and Apache Cordova. This documentation is mainly for my purposes of remembering but it should be useful if you want to start a project with these technologies.
This project was based off of the phaser-es6-boilerplate
- Gulp script for autobuilding, running unit tests, and local project hosting
- Karma unit tests
- Module support using browserify
- ES6 Support using babelify
- Source maps
- Texture atlas and texture atlas export script for GIMP
- Auto display sizing to your game's desired aspect ratio
cd ~/dev
git clone [email protected]:seanirby/phaser-cordova-template.git
cd phaser-cordova-template
npm update
npm install
cordova platform add ios
cordova platform add android
To start the dev autobuild/test process, you need to run the following from the project directory.
npm start
Before you can build the iOS mobile executable you must edit build.json
to provide your development team id. This can be found in your developer portal. Once that is done, run the following to start your project:
cordova build ios
cordova run ios
Contains assets that may need some processing before being placed in
the static
folder.
For instance, asset_projects/gfx
contains a GIMP
project named atlas
where you can draw your game's graphics. Each
layer in this file corresponds to a game sprite. Export the atlas to
the static
folder by running the gimp script in
gimp_scripts/make_atlas_files.scm
.
Cordova specific. See cordova docs
Cordova specific. See cordova docs
This file defines a script that builds your project, autobuilds on
changes, and runs your unit tests. The project is compiled from the
content in src
, static
, node_modules/phaser
, and
node_modules/javascript-state-machine
. Tests are run found in
tests
folder.
The compiled assets can be found in www
. See script for details.
Cordova specific. See cordova docs
Cordova specific. See cordova docs
Unit test configuration
npm configuration file
Cordova specific. See cordova docs
Cordova specific. See cordova docs
Helper file for starting up a local web server serving content in the
www
directory. This is useful if you need to send the game to an
artist who needs to test the game but may not be technical. All they
need to do is run the following command from the project folder.
ruby server.rb
You should be able to see the project on http://localhost:8001
.
Folder for source files that need some form of compilation. Currently
it contains the project's JS files and index.html
. The javascript
files in this folder support ES6 syntax and will be compiled into
www/game.js
after building.
The html file in this folder will be
compiled into www/index.html
after building. The html file is
preprocessed in the gulpfile so you can conditionally place content
in index.html
if you wish.
Project assets such as sound files, images, and stylesheets. These
files are simply copied into the www
directory when built.
Directory for storing your Karma unit tests
Project build folder.
Our application code starts in src/js/index.js
with the call to app.initialize()
. This sets up the event callback we need to start our game. For desktop/non-mobile users, we listen for the DOMContentLoaded
event. For mobile users we listen for the deviceready
event. These callbacks will perform any context specific setup and then start the game.
The game states can be found in src/js/states
. This template is set to execute the following sequence of states on startup.
- Boot
- Preload
- ScreenTest
The ScreenTest
state displays information about your window dimensions and device dimensions. Once you start development on your game, you will want to edit the Preload
state so you don't immediately go to the ScreenTest
.