2013-08-29 20:57:36 +00:00
|
|
|
Phaser.World = function (game) {
|
|
|
|
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
this._stage = new PIXI.Stage(0x000000);
|
|
|
|
|
|
|
|
this._container = new PIXI.DisplayObjectContainer();
|
|
|
|
|
|
|
|
this._stage.addChild(this._container);
|
2013-08-29 21:53:55 +00:00
|
|
|
|
|
|
|
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
|
2013-08-29 20:57:36 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.World.prototype = {
|
|
|
|
|
|
|
|
_stage: null,
|
|
|
|
_container: null,
|
2013-08-30 17:56:10 +00:00
|
|
|
_length: 0,
|
2013-08-29 20:57:36 +00:00
|
|
|
|
|
|
|
bounds: null,
|
2013-08-31 12:54:59 +00:00
|
|
|
camera: null,
|
|
|
|
|
|
|
|
boot: function () {
|
|
|
|
|
|
|
|
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
|
2013-08-31 20:50:34 +00:00
|
|
|
this.game.camera = this.camera;
|
2013-08-31 12:54:59 +00:00
|
|
|
|
|
|
|
},
|
2013-08-29 20:57:36 +00:00
|
|
|
|
2013-08-29 21:53:55 +00:00
|
|
|
add: function (gameobject) {
|
|
|
|
this._container.addChild(gameobject);
|
2013-08-30 16:09:43 +00:00
|
|
|
return gameobject;
|
2013-08-29 21:53:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addAt: function (gameobject, index) {
|
|
|
|
this._container.addChildAt(gameobject, index);
|
2013-08-30 16:09:43 +00:00
|
|
|
return gameobject;
|
2013-08-29 21:53:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getAt: function (index) {
|
|
|
|
return this._container.getChildAt(index);
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function (gameobject) {
|
|
|
|
this._container.removeChild(gameobject);
|
2013-08-30 16:09:43 +00:00
|
|
|
return gameobject;
|
2013-08-29 20:57:36 +00:00
|
|
|
},
|
|
|
|
|
2013-08-30 17:56:10 +00:00
|
|
|
update: function () {
|
|
|
|
|
2013-08-31 12:54:59 +00:00
|
|
|
this.camera.update();
|
|
|
|
|
2013-09-01 02:57:24 +00:00
|
|
|
var displayObject = this._stage;
|
|
|
|
|
|
|
|
// once the display object hits this. we can break the loop
|
|
|
|
var testObject = displayObject.last._iNext;
|
|
|
|
displayObject = displayObject.first;
|
|
|
|
|
|
|
|
do
|
2013-08-30 17:56:10 +00:00
|
|
|
{
|
2013-09-01 02:57:24 +00:00
|
|
|
if (displayObject['update'])
|
|
|
|
{
|
|
|
|
displayObject.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// count++
|
|
|
|
displayObject = displayObject._iNext;
|
2013-08-30 17:56:10 +00:00
|
|
|
}
|
2013-09-01 02:57:24 +00:00
|
|
|
while(displayObject != testObject)
|
2013-08-30 17:56:10 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-29 20:57:36 +00:00
|
|
|
/**
|
|
|
|
* Updates the size of this world.
|
|
|
|
*
|
|
|
|
* @param width {number} New width of the world.
|
|
|
|
* @param height {number} New height of the world.
|
|
|
|
*/
|
2013-08-31 12:54:59 +00:00
|
|
|
setSize: function (width, height) {
|
2013-08-29 20:57:36 +00:00
|
|
|
|
|
|
|
this.bounds.width = width;
|
|
|
|
this.bounds.height = height;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Getters / Setters
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.World.prototype, "width", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this.bounds.width;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this.bounds.width = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.World.prototype, "height", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this.bounds.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this.bounds.height = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.World.prototype, "centerX", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this.bounds.halfWidth;
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.World.prototype, "centerY", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this.bounds.halfHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.World.prototype, "randomX", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return Math.round(Math.random() * this.bounds.width);
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.World.prototype, "randomY", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return Math.round(Math.random() * this.bounds.height);
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|