2016-10-09 22:39:27 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2016-10-19 10:54:00 +00:00
|
|
|
/**
|
|
|
|
* This is the base Game Object class that you can use when creating your own extended Game Objects.
|
|
|
|
* It hides away the 'private' stuff and exposes only the useful getters, setters and properties.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
|
|
|
// Phaser.Texture and Phaser.Frame objects passed in here, instead of looked-up.
|
|
|
|
// Allows override from non-standard GO types
|
2016-11-08 01:50:57 +00:00
|
|
|
Phaser.GameObject = function (state, x, y, texture, frame, parent)
|
2016-10-09 22:39:27 +00:00
|
|
|
{
|
2016-11-08 01:50:57 +00:00
|
|
|
this.state = state;
|
|
|
|
|
|
|
|
this.game = state.game;
|
2016-10-09 22:39:27 +00:00
|
|
|
|
2016-10-14 07:59:24 +00:00
|
|
|
this.name = '';
|
|
|
|
|
2016-10-19 10:54:00 +00:00
|
|
|
this.type = 0;
|
|
|
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
|
|
// Texture is globally shared between GameObjects, not specific to this one
|
|
|
|
this.texture = texture;
|
|
|
|
|
|
|
|
// Frame is globally shared between GameObjects, not specific to this one
|
|
|
|
this.frame = frame;
|
|
|
|
|
|
|
|
// All GameObjects have the following components, always:
|
|
|
|
this.transform = new Phaser.Component.Transform(this, x, y);
|
|
|
|
|
|
|
|
// Optional? Maybe set on a per GO basis?
|
|
|
|
this.data = new Phaser.Component.Data(this);
|
2016-10-14 07:59:24 +00:00
|
|
|
|
2016-10-19 10:54:00 +00:00
|
|
|
this.color = new Phaser.Component.Color(this);
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// The following properties are debatable to have in this class
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
|
|
|
this.scaleMode = Phaser.scaleModes.DEFAULT;
|
|
|
|
|
|
|
|
// Allows you to turn off a GameObject from rendering, but still render its children (if it has any)
|
|
|
|
// Maybe this should move?
|
|
|
|
// this.skipRender = (key === undefined);
|
|
|
|
this.skipRender = false;
|
|
|
|
|
|
|
|
this.visible = true;
|
|
|
|
|
|
|
|
// Either null, or the Children component
|
2016-10-09 22:39:27 +00:00
|
|
|
this.children = null;
|
|
|
|
|
2016-10-19 10:54:00 +00:00
|
|
|
this.exists = true;
|
2016-10-14 07:59:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.GameObject.prototype.constructor = Phaser.GameObject;
|
|
|
|
|
|
|
|
Phaser.GameObject.prototype = {
|
|
|
|
|
|
|
|
preUpdate: function ()
|
|
|
|
{
|
|
|
|
// NOOP
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function ()
|
|
|
|
{
|
|
|
|
// NOOP
|
|
|
|
},
|
|
|
|
|
|
|
|
postUpdate: function ()
|
|
|
|
{
|
|
|
|
// NOOP
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function ()
|
2016-10-19 10:54:00 +00:00
|
|
|
{
|
|
|
|
// NOOP
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function ()
|
2016-10-14 07:59:24 +00:00
|
|
|
{
|
|
|
|
// NOOP
|
|
|
|
}
|
2016-10-09 22:39:27 +00:00
|
|
|
|
|
|
|
};
|
2016-10-19 10:54:00 +00:00
|
|
|
|
|
|
|
Object.defineProperties(Phaser.GameObject.prototype, {
|
|
|
|
|
|
|
|
// Transform getters / setters
|
|
|
|
|
|
|
|
x: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._posX;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._posX = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
y: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._posY;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._posY = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
scale: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._scaleX;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._scaleX = value;
|
|
|
|
this.transform._scaleY = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
this.transform.updateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
scaleX: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._scaleX;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._scaleX = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
this.transform.updateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
scaleY: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._scaleY;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._scaleY = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
this.transform.updateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
anchor: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._anchorX;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2016-10-27 14:14:09 +00:00
|
|
|
this.transform.setAnchor(value);
|
2016-10-19 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
anchorX: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._anchorX;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._anchorX = value;
|
2016-10-27 14:14:09 +00:00
|
|
|
this.transform.dirty = true;
|
2016-10-19 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
anchorY: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._anchorY;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._anchorY = value;
|
2016-10-27 14:14:09 +00:00
|
|
|
this.transform.dirty = true;
|
2016-10-19 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
pivotX: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._pivotX;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._pivotX = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
this.transform.updateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
pivotY: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._pivotY;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.transform._pivotY = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
this.transform.updateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
angle: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
rotation: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._rotation;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
if (this.transform._rotation === value)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.transform._rotation = value;
|
|
|
|
this.transform.dirty = true;
|
|
|
|
|
|
|
|
if (this.transform._rotation % Phaser.Math.PI2)
|
|
|
|
{
|
|
|
|
this.transform.cache.sr = Math.sin(this.transform._rotation);
|
|
|
|
this.transform.cache.cr = Math.cos(this.transform._rotation);
|
|
|
|
this.transform.updateCache();
|
|
|
|
this.transform.hasLocalRotation = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.transform.hasLocalRotation = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// Color getters / setters
|
|
|
|
|
|
|
|
alpha: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.color._alpha;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.color.alpha = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
blendMode: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.color._blendMode;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.color.blendMode = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|