Skip to content

Commit

Permalink
Game Objects all now using the new Components mixins.
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Feb 17, 2015
1 parent 4bb1adc commit 167bbde
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 4,419 deletions.
250 changes: 20 additions & 230 deletions src/gameobjects/BitmapText.js
Expand Up @@ -29,39 +29,12 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
text = text || '';
size = size || 32;

/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;

/**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default
*/
this.exists = true;

/**
* @property {string} name - The user defined name given to this BitmapText.
* @default
*/
this.name = '';

/**
* @property {number} type - The const type of this object.
* @readonly
*/
this.type = Phaser.BITMAPTEXT;

/**
* @property {number} z - The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
*/
this.z = 0;

/**
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
*/
this.world = new Phaser.Point(x, y);

/**
* @property {string} _text - Internal cache var.
* @private
Expand Down Expand Up @@ -92,56 +65,25 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
*/
this._tint = 0xFFFFFF;

/**
* @property {Phaser.Events} events - The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
*/
this.events = new Phaser.Events(this);

/**
* @property {Phaser.InputHandler|null} input - The Input Handler for this object. Needs to be enabled with image.inputEnabled = true before you can use it.
*/
this.input = null;

/**
* @property {Phaser.Point} cameraOffset - If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.
*/
this.cameraOffset = new Phaser.Point();

PIXI.BitmapText.call(this, text);

this.position.set(x, y);
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);

/**
* @property {Phaser.Point} previousPosition - The position the Sprite was in at the last update.
* @readOnly
*/
this.previousPosition = new Phaser.Point(x, y);
var components = [
'Angle',
'AutoCull',
'Bounds',
'Destroy',
'FixedToCamera',
'InputEnabled',
'InWorld',
'LifeSpan',
'PhysicsBody',
'Reset'
];

/**
* @property {number} previousRotation - The rotation angle the Sprite was in at the last update (in radians)
* @readOnly
*/
this.previousRotation = 0;

/**
* @property {number} renderOrderID - The render order ID. This is used internally by the renderer and input manager and should not be modified.
* @readOnly
*/
this.renderOrderID = 0;

/**
* A Sprite that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Sprite.cameraOffset.
* Note that the cameraOffset values are in addition to any parent in the display list.
* So if this Sprite was in a Group that has x: 200, then this will be added to the cameraOffset.x
* @property {boolean} fixedToCamera
*/
this.fixedToCamera = false;

/**
* @property {boolean} destroyPhase - As a Sprite runs through its destroy method this flag is set to true, and can be checked in any sub-systems it is being destroyed from.
* @readOnly
*/
this.destroyPhase = false;
Phaser.Component.Core.install.call(this, components);
Phaser.Component.Core.init.call(this, game, x, y, '', null);

};

Expand All @@ -167,113 +109,21 @@ Phaser.BitmapText.prototype.setStyle = function() {
*/
Phaser.BitmapText.prototype.preUpdate = function () {

this.previousPosition.set(this.world.x, this.world.y);
this.previousRotation = this.rotation;

if (!this.exists || !this.parent.exists)
{
this.renderOrderID = -1;
return false;
}

if (this.autoCull)
{
// Won't get rendered but will still get its transform updated
this.renderable = this.game.world.camera.screenView.intersects(this.getBounds());
}

this.world.setTo(this.game.camera.x + this.worldTransform.tx, this.game.camera.y + this.worldTransform.ty);

if (this.visible)
{
this.renderOrderID = this.game.stage.currentRenderOrderID++;
}
Phaser.Component.InWorld.preUpdate.call(this);
Phaser.Component.Core.preUpdate.call(this);

return true;

};

/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*
* @method Phaser.BitmapText.prototype.update
*/
Phaser.BitmapText.prototype.update = function() {

};

/**
* Automatically called by World.postUpdate.
* Automatically called by World.preUpdate.
* @method Phaser.BitmapText.prototype.postUpdate
*/
Phaser.BitmapText.prototype.postUpdate = function () {

// Fixed to Camera?
if (this.fixedToCamera)
{
this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
}

};

/**
* Destroy this BitmapText instance. This will remove any filters and un-parent any children.
* @method Phaser.BitmapText.prototype.destroy
* @param {boolean} [destroyChildren=true] - Should every child of this object have its destroy method called?
*/
Phaser.BitmapText.prototype.destroy = function(destroyChildren) {

if (this.game === null || this.destroyPhase) { return; }

if (typeof destroyChildren === 'undefined') { destroyChildren = true; }

this.destroyPhase = true;

if (this.parent)
{
if (this.parent instanceof Phaser.Group)
{
this.parent.remove(this);
}
else
{
this.parent.removeChild(this);
}
}

var i = this.children.length;

if (destroyChildren)
{
while (i--)
{
if (this.children[i].destroy)
{
this.children[i].destroy(destroyChildren);
}
else
{
this.removeChild(this.children[i]);
}
}
}
else
{
while (i--)
{
this.removeChild(this.children[i]);
}
}

this.exists = false;
this.visible = false;

this.filters = null;
this.mask = null;
this.game = null;

this.destroyPhase = false;
Phaser.Component.PhysicsBody.postUpdate.call(this);
Phaser.Component.FixedToCamera.postUpdate.call(this);

};

Expand Down Expand Up @@ -321,25 +171,6 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'tint', {

});

/**
* Indicates the rotation of the Text, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
* @name Phaser.BitmapText#angle
* @property {number} angle - Gets or sets the angle of rotation in degrees.
*/
Object.defineProperty(Phaser.BitmapText.prototype, 'angle', {

get: function() {
return Phaser.Math.radToDeg(this.rotation);
},

set: function(value) {
this.rotation = Phaser.Math.degToRad(value);
}

});

/**
* @name Phaser.BitmapText#font
* @property {string} font - The font the text will be rendered in, i.e. 'Arial'. Must be loaded in the browser before use.
Expand Down Expand Up @@ -411,44 +242,3 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'text', {
}

});

/**
* By default a Text object won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
* activated for this object and it will then start to process click/touch events and more.
*
* @name Phaser.BitmapText#inputEnabled
* @property {boolean} inputEnabled - Set to true to allow this object to receive input events.
*/
Object.defineProperty(Phaser.BitmapText.prototype, "inputEnabled", {

get: function () {

return (this.input && this.input.enabled);

},

set: function (value) {

if (value)
{
if (this.input === null)
{
this.input = new Phaser.InputHandler(this);
this.input.start();
}
else if (this.input && !this.input.enabled)
{
this.input.start();
}
}
else
{
if (this.input && this.input.enabled)
{
this.input.stop();
}
}

}

});
1 change: 0 additions & 1 deletion src/gameobjects/Button.js
Expand Up @@ -217,7 +217,6 @@ var STATE_OUT = 'Out';
var STATE_DOWN = 'Down';
var STATE_UP = 'Up';


/**
* Clears all of the frames set on this Button.
*
Expand Down

0 comments on commit 167bbde

Please sign in to comment.