Phaser runtime is an application to run Phaser.js games on desktop. Phase runtime works with Electron.
[sudo] npm install -g phaser-runtime
cd path/to/game
phaser
The project must be a directory that contains an index.js
file with Phaser code and a package.json
file with the window configuration according to the Electron BrowserWindow documentation.
The Game
function returns a Phaser game object.
Game(renderer, state, transparent, antialias, physicsConfig);
var game = Game(Phaser.CANVAS, {create: create});
You can import modules using the require
function.
var fs = require("fs");
You must have to use __dirname
to refers to the game directory
game.load.image('progress', __dirname+'/img/progress.png');
myGame
└---package.json
└---index.js
You can generate a
package.json
withnpm init
command
{
"name": "demo",
"version": "1.0.0",
"description": "Phaser Runtime Demo",
"license": "ISC",
"window": {
"width": 800,
"height": 600,
"title": "My Game"
}
}
var game = Game(Phaser.CANVAS, { create: create, render: render });
var circle;
function create() {
circle = new Phaser.Circle(game.world.centerX, 100, 64);
}
function render () {
game.debug.geom(circle, '#cfffff');
game.debug.text('Diameter : ' + circle.diameter, 50, 200);
game.debug.text('Circumference : ' + circle.circumference(), 50, 230);
}
To run the game, enter phaser
inside the "myGame" directory.
- F12 to open the dev tools.
- F5 to refresh the browser window