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="http://www.neurofuzzy.net/libs/phaser/2.2.0/phaser.min.js"></script>
<div id="game_div"> </div>
CSS
#game_div {
width: 400px;
margin: auto;
margin-top: 50px;
}
JavaScript
// Phaser.TilemapLayer.prototype.shiftCanvas
// context.globalCompositeOperation = 'copy';
// seems to be breaking TileMaps in Safari
// EXAMPLE
var game = new Phaser.Game(400, 490, Phaser.CANVAS, 'game_div');
var game_state = { };
// Creates a new 'main' state that wil contain the game
game_state.main = function() { };
game_state.main.prototype = {
data: {},
current: {},
prevDragPoint: null,
preload: function() {
// Function called first to load all the assets
game.load.image('skies', 'http://sploder.servegame.org:3000/gamedata/first/02/images/skies.png');
},
create: function() {
var v = this.current;
this.game.world.setBounds(0, 0, 192 * 16, 64 * 16);
v.skymap = this.add.tilemap();
v.skymap.addTilesetImage('skies', 'skies', 16, 256);
v.sky = v.skymap.create('sky', 32, 1, 16, 256);
v.sky.scale = { x: 4, y: 4 };
v.sky.scrollFactorX = v.sky.scrollFactorY = 0.125;
for (var i = 0; i < 32; i++) v.skymap.putTile(Math.floor(Math.random() * 4), i, 0, 'sky');
},
update: function() {
this.dragWorld();
},
dragWorld: function () {
var pointer = this.game.input.mousePointer;
if (!pointer.timeDown) pointer = this.game.input.pointer1;
if (!pointer.timeDown) return;
if (pointer.isDown && !pointer.targetObject) {
if (this.prevDragPoint) {
this.game.camera.x += this.prevDragPoint.x - pointer.position.x;
this.game.camera.y += this.prevDragPoint.y - pointer.position.y;
}
this.prevDragPoint = pointer.position.clone();
}
if (pointer.isUp) this.prevDragPoint = null;
}
};
// Add and start the 'main' state to start the game
game.state.add('main', game_state.main);
game.state.start('main');