Hello World Phaser Example

Kudos Thomas Palef: http://www.lessmilk.com/ http://blog.lessmilk.com/how-to-make-flappy-bird-in-html5-1/

HTML

<script src="https://github.com/photonstorm/phaser/releases/download/v2.4.4/phaser.min.js"></script>
<div id="game_div"> </div>

CSS

#game_div {
      width: 400px;
      margin: auto;
      margin-top: 50px;
    }

JavaScript

// Initialize Phaser, and creates a 400x490px game
var game = new Phaser.Game(400, 490, Phaser.CANVAS, 'game_div');
var game_state = {};

// player.js

var HardDrive = HardDrive || {};
 
HardDrive.Player = function (game, x, y) {
 	 
    console.log(game,x,y)
    Phaser.Sprite.call(this, game, x, y, 'car');
    console.log("this", this)
    game.add.existing(this);
};
 
HardDrive.Player.prototype = Object.create(Phaser.Sprite.prototype);
HardDrive.Player.constructor = HardDrive.Player;
 
HardDrive.Player.prototype.create = function () {
 
    this.game.physics.enable(this.car, Phaser.Physics.ARCADE);
    this.car.anchor.setTo(0.5, 0.5);
}

// game.js

var HardDrive = HardDrive || {};
 
HardDrive.game = function () {
 
};
 
HardDrive.game.prototype = {
    
    preload: function() {
        console.log("preload");
    	game.load.image('car', 'http://s3.amazonaws.com/uploads-1969f46zwpmbh5cm3kr2/hello.png');
    },
    
    create: function () {
 	   console.log("create");
       new HardDrive.Player(game,200, 200);
    }
}
// 

game.state.add('main', HardDrive.game);  
game.state.start('main');