Example
- Create a folder where you would like to have your game live, and move into that
mkdir my-new-game
cd my-new-game
- Initialize the directory using npm.
npm init -y
- Install phaser as a node package.
npm install phaser
- Install http-server as a global module, to be used on the commandline.
npm install -g http-server
- Create an index.html file and reference the Phaser executable and paste the following code into it.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My Gamer</title>
<script type="text/javascript" src="node_modules/phaser/build/phaser.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<div id="helloWorld"></div>
</body>
<script>
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'helloWorld', {
create: create
});
function create() {
var text = "Hello World!";
var style = {
font: "65px Arial",
fill: "#ff0044",
align: "center"
};
var t = game.add.text(game.world.centerX, 300, text, style);
t.anchor.set(0.5);
}
</script>
</html>
- Start the server and load http://localhost:8080 in your browser!
hs