mirror of
https://github.com/wassname/phaser.git
synced 2026-08-12 12:20:38 +08:00
World and Camera updates nearly complete.
This commit is contained in:
+2
-4
@@ -180,8 +180,6 @@ Phaser.Camera.prototype = {
|
||||
this.updateTarget();
|
||||
}
|
||||
|
||||
this.updateTarget();
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.checkBounds();
|
||||
@@ -325,7 +323,7 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
|
||||
set: function (value) {
|
||||
|
||||
this.view.x = value;
|
||||
this.displayObject.x = -value;
|
||||
this.displayObject.position.x = -value;
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
@@ -349,7 +347,7 @@ Object.defineProperty(Phaser.Camera.prototype, "y", {
|
||||
set: function (value) {
|
||||
|
||||
this.view.y = value;
|
||||
this.displayObject.y = -value;
|
||||
this.displayObject.position.y = -value;
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
|
||||
+2
-2
@@ -297,14 +297,14 @@ Phaser.Game.prototype = {
|
||||
this.net = new Phaser.Net(this);
|
||||
this.debug = new Phaser.Utils.Debug(this);
|
||||
|
||||
this.load.onLoadComplete.add(this.loadComplete, this);
|
||||
|
||||
this.stage.boot();
|
||||
this.world.boot();
|
||||
this.input.boot();
|
||||
this.sound.boot();
|
||||
this.state.boot();
|
||||
|
||||
this.load.onLoadComplete.add(this.loadComplete, this);
|
||||
|
||||
if (this.renderType == Phaser.CANVAS)
|
||||
{
|
||||
console.log('%cPhaser ' + Phaser.VERSION + ' initialized. Rendering to Canvas', 'color: #ffff33; background: #000000');
|
||||
|
||||
+6
-1
@@ -70,7 +70,12 @@ Phaser.Group = function (game, parent, name, useStage) {
|
||||
* @default
|
||||
*/
|
||||
this.exists = true;
|
||||
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one.
|
||||
*/
|
||||
this.scale = new Phaser.Point(1, 1);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Group.prototype = {
|
||||
|
||||
+95
-96
@@ -17,10 +17,12 @@
|
||||
*/
|
||||
Phaser.World = function (game) {
|
||||
|
||||
Phaser.Group.call(this, game, null, '__world', false);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
* @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one.
|
||||
*/
|
||||
this.scale = new Phaser.Point(1, 1);
|
||||
|
||||
/**
|
||||
* The World has no fixed size, but it does have a bounds outside of which objects are no longer considered as being "in world" and you should use this to clean-up the display list and purge dead objects.
|
||||
@@ -41,120 +43,117 @@ Phaser.World = function (game) {
|
||||
*/
|
||||
this.currentRenderOrderID = 0;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Group} group - Object container stores every object created with `create*` methods.
|
||||
*/
|
||||
this.group = null;
|
||||
|
||||
};
|
||||
|
||||
Phaser.World.prototype = {
|
||||
Phaser.World.prototype = Object.create(Phaser.Group.prototype);
|
||||
Phaser.World.prototype.constructor = Phaser.World;
|
||||
|
||||
/**
|
||||
* Initialises the game world.
|
||||
*
|
||||
* @method Phaser.World#boot
|
||||
* @protected
|
||||
*/
|
||||
boot: function () {
|
||||
/**
|
||||
* Initialises the game world.
|
||||
*
|
||||
* @method Phaser.World#boot
|
||||
* @protected
|
||||
*/
|
||||
Phaser.World.prototype.boot = function () {
|
||||
|
||||
this.group = new Phaser.Group(this.game, null, '__world');
|
||||
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
|
||||
|
||||
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
|
||||
this.camera.displayObject = this.group;
|
||||
this.camera.displayObject = this._container;
|
||||
|
||||
this.game.camera = this.camera;
|
||||
this.game.camera = this.camera;
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called automatically every frame, and is where main logic happens.
|
||||
*
|
||||
* @method Phaser.World#update
|
||||
*/
|
||||
update: function () {
|
||||
/**
|
||||
* This is called automatically every frame, and is where main logic happens.
|
||||
*
|
||||
* @method Phaser.World#update
|
||||
*/
|
||||
Phaser.World.prototype.update = function () {
|
||||
|
||||
this.camera.update();
|
||||
this.camera.update();
|
||||
|
||||
this.currentRenderOrderID = 0;
|
||||
this.currentRenderOrderID = 0;
|
||||
|
||||
if (this.game.stage._stage.first._iNext)
|
||||
if (this.game.stage._stage.first._iNext)
|
||||
{
|
||||
var currentNode = this.game.stage._stage.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
var currentNode = this.game.stage._stage.first._iNext;
|
||||
|
||||
do
|
||||
if (currentNode['preUpdate'])
|
||||
{
|
||||
if (currentNode['preUpdate'])
|
||||
{
|
||||
currentNode.preUpdate();
|
||||
}
|
||||
|
||||
if (currentNode['update'])
|
||||
{
|
||||
currentNode.update();
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
currentNode.preUpdate();
|
||||
}
|
||||
while (currentNode != this.game.stage._stage.last._iNext)
|
||||
|
||||
if (currentNode['update'])
|
||||
{
|
||||
currentNode.update();
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this.game.stage._stage.last._iNext)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called automatically every frame, and is where main logic happens.
|
||||
* @method Phaser.World#postUpdate
|
||||
*/
|
||||
postUpdate: function () {
|
||||
/**
|
||||
* This is called automatically every frame, and is where main logic happens.
|
||||
* @method Phaser.World#postUpdate
|
||||
*/
|
||||
Phaser.World.prototype.postUpdate = function () {
|
||||
|
||||
if (this.game.stage._stage.first._iNext)
|
||||
if (this.game.stage._stage.first._iNext)
|
||||
{
|
||||
var currentNode = this.game.stage._stage.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
var currentNode = this.game.stage._stage.first._iNext;
|
||||
|
||||
do
|
||||
if (currentNode['postUpdate'])
|
||||
{
|
||||
if (currentNode['postUpdate'])
|
||||
{
|
||||
currentNode.postUpdate();
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
currentNode.postUpdate();
|
||||
}
|
||||
while (currentNode != this.game.stage._stage.last._iNext)
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the size of this world. Note that this doesn't modify the world x/y coordinates, just the width and height.
|
||||
* If you need to adjust the bounds of the world
|
||||
* @method Phaser.World#setSize
|
||||
* @param {number} width - New width of the world.
|
||||
* @param {number} height - New height of the world.
|
||||
*/
|
||||
setSize: function (width, height) {
|
||||
|
||||
this.bounds.width = width;
|
||||
this.bounds.height = height;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroyer of worlds.
|
||||
* @method Phaser.World#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
this.camera.x = 0;
|
||||
this.camera.y = 0;
|
||||
|
||||
this.game.input.reset(true);
|
||||
|
||||
this.group.removeAll();
|
||||
|
||||
while (currentNode != this.game.stage._stage.last._iNext)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the size of this world. Note that this doesn't modify the world x/y coordinates, just the width and height.
|
||||
* If you need to adjust the bounds of the world
|
||||
* @method Phaser.World#setSize
|
||||
* @param {number} width - New width of the world.
|
||||
* @param {number} height - New height of the world.
|
||||
*/
|
||||
Phaser.World.prototype.setBounds = function (x, y, width, height) {
|
||||
|
||||
this.bounds.setTo(x, y, width, height);
|
||||
|
||||
if (this.camera.bounds)
|
||||
{
|
||||
this.camera.bounds.setTo(x, y, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroyer of worlds.
|
||||
* @method Phaser.World#destroy
|
||||
*/
|
||||
Phaser.World.prototype.destroy = function () {
|
||||
|
||||
this.camera.x = 0;
|
||||
this.camera.y = 0;
|
||||
|
||||
this.game.input.reset(true);
|
||||
|
||||
this.removeAll();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Phaser.World#width
|
||||
@@ -222,7 +221,7 @@ Object.defineProperty(Phaser.World.prototype, "centerY", {
|
||||
Object.defineProperty(Phaser.World.prototype, "randomX", {
|
||||
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.width);
|
||||
return this.game.rnd.integerInRange(this.bounds.x, this.bounds.width);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -235,7 +234,7 @@ Object.defineProperty(Phaser.World.prototype, "randomX", {
|
||||
Object.defineProperty(Phaser.World.prototype, "randomY", {
|
||||
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.height);
|
||||
return this.game.rnd.integerInRange(this.bounds.y, this.bounds.height);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
existing: function (object) {
|
||||
|
||||
return this.world.group.add(object);
|
||||
return this.world.add(object);
|
||||
|
||||
},
|
||||
|
||||
@@ -64,7 +64,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
sprite: function (x, y, key, frame) {
|
||||
|
||||
return this.world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
||||
return this.world.create(x, y, key, frame);
|
||||
|
||||
},
|
||||
|
||||
@@ -72,17 +72,20 @@ Phaser.GameObjectFactory.prototype = {
|
||||
* Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent.
|
||||
*
|
||||
* @method child
|
||||
* @param {Phaser.Group} group - The Group to add this child to.
|
||||
* @param {number} x - X position of the new sprite.
|
||||
* @param {number} y - Y position of the new sprite.
|
||||
* @param {string|RenderTexture} [key] - The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture.
|
||||
* @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @returns {Description} Description.
|
||||
*/
|
||||
child: function (parent, x, y, key, frame) {
|
||||
child: function (group, x, y, key, frame) {
|
||||
|
||||
var child = this.world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
||||
parent.addChild(child);
|
||||
return child;
|
||||
return group.create(x, y, key, frame);
|
||||
|
||||
// var child = new Phaser.Sprite(this.game, x, y, key, frame);
|
||||
// parent.addChild(child);
|
||||
// return child;
|
||||
|
||||
},
|
||||
|
||||
@@ -142,7 +145,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
tileSprite: function (x, y, width, height, key, frame) {
|
||||
|
||||
return this.world.group.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
|
||||
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
|
||||
|
||||
},
|
||||
|
||||
@@ -157,7 +160,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
text: function (x, y, text, style) {
|
||||
|
||||
return this.world.group.add(new Phaser.Text(this.game, x, y, text, style));
|
||||
return this.world.add(new Phaser.Text(this.game, x, y, text, style));
|
||||
|
||||
},
|
||||
|
||||
@@ -176,7 +179,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
|
||||
|
||||
return this.world.group.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
|
||||
return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
|
||||
|
||||
},
|
||||
|
||||
@@ -190,7 +193,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
graphics: function (x, y) {
|
||||
|
||||
return this.world.group.add(new Phaser.Graphics(this.game, x, y));
|
||||
return this.world.add(new Phaser.Graphics(this.game, x, y));
|
||||
|
||||
},
|
||||
|
||||
@@ -221,7 +224,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
bitmapText: function (x, y, text, style) {
|
||||
|
||||
return this.world.group.add(new Phaser.BitmapText(this.game, x, y, text, style));
|
||||
return this.world.add(new Phaser.BitmapText(this.game, x, y, text, style));
|
||||
|
||||
},
|
||||
|
||||
@@ -239,7 +242,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
*/
|
||||
tilemap: function (x, y, key, resizeWorld, tileWidth, tileHeight) {
|
||||
|
||||
return this.world.group.add(new Phaser.Tilemap(this.game, key, x, y, resizeWorld, tileWidth, tileHeight));
|
||||
return this.world.add(new Phaser.Tilemap(this.game, key, x, y, resizeWorld, tileWidth, tileHeight));
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user