Lots of documentation updates and new Loader examples.

This commit is contained in:
photonstorm
2013-11-27 16:33:49 +00:00
parent 4926fac578
commit a9a46bfbbf
27 changed files with 1047 additions and 203 deletions
+55
View File
@@ -0,0 +1,55 @@
GameState = function (game) {
this.game = game;
};
GameState.prototype = Object.create(Phaser.State.prototype);
GameState.prototype.constructor = GameState;
GameState.prototype.preload = function preload() {
this.game.load.image('bunny', 'assets/sprites/bunny.png');
this.game.load.image('carrot', 'assets/sprites/carrot.png');
this.game.load.image('melon', 'assets/sprites/melon.png');
}
GameState.prototype.create = function () {
this.game.world.setBounds(0, 0, 1600, 600);
this.bunny = this.game.add.sprite(200, 200, 'bunny');
this.bunny.scale.setTo(0.2, 0.2);
var melon = this.game.add.sprite(0, 0, 'melon');
this.melonGroup = this.game.add.group(null, 'melonGroup');
this.melonGroup.add(melon);
melon.x = this.bunny.x;
melon.y = this.bunny.y - 40;
this.carrot = this.game.add.sprite(0, 0, 'carrot');
this.game.camera.follow(this.bunny);
}
GameState.prototype.update = function () {
this.bunny.body.velocity.x = 0;
if (this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
this.bunny.body.velocity.x = 500;
}
if (this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
this.bunny.body.velocity.x = -500;
}
// var melon = this.melonGroup.getFirstExists(true);
// melon.x = this.bunny.x;
// melon.y = this.bunny.y - 40;
this.carrot.x = this.bunny.x;
this.carrot.y = this.bunny.y - 20;
};
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example');
game.state.add('state', GameState, true);
})();
+3 -1
View File
@@ -32,6 +32,8 @@ var button6;
function create() {
console.log('create!');
background = game.add.sprite(0, 0, 'sky0');
background.name = 'background';
@@ -77,7 +79,7 @@ function create() {
// Phaser.Canvas.setSmoothingEnabled(false);
game.input.onDown.add(gofull, this);
//game.input.onDown.add(gofull, this);
}