phaser/wip/components/BaseTransform.js

247 lines
4.6 KiB
JavaScript
Raw Normal View History

2016-10-12 22:53:39 +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}
*/
/**
* A BaseTransform class that you can use when extending Game Objects.
* Hides away the 'private' stuff and exposes only the useful getters and setters
*
* @class
*/
Phaser.Component.BaseTransform = function (x, y)
{
this.transform = new Phaser.Component.Transform(this, x, y);
};
Phaser.Component.BaseTransform.prototype.constructor = Phaser.Component.BaseTransform;
Object.defineProperties(Phaser.Component.BaseTransform.prototype, {
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;
}
},
2016-10-13 00:54:30 +00:00
scale: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
return this.transform._scaleX;
},
set: function (value)
{
this.transform._scaleX = value;
2016-10-13 00:54:30 +00:00
this.transform._scaleY = value;
2016-10-12 22:53:39 +00:00
this.transform.dirty = true;
this.transform.updateCache();
}
},
2016-10-13 00:54:30 +00:00
scaleX: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._scaleX;
2016-10-12 22:53:39 +00:00
},
set: function (value)
{
2016-10-13 00:54:30 +00:00
this.transform._scaleX = value;
2016-10-12 22:53:39 +00:00
this.transform.dirty = true;
this.transform.updateCache();
}
},
2016-10-13 00:54:30 +00:00
scaleY: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._scaleY;
2016-10-12 22:53:39 +00:00
},
set: function (value)
{
2016-10-13 00:54:30 +00:00
this.transform._scaleY = value;
2016-10-12 22:53:39 +00:00
this.transform.dirty = true;
this.transform.updateCache();
}
},
2016-10-13 00:54:30 +00:00
anchor: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._anchorX;
2016-10-12 22:53:39 +00:00
},
set: function (value)
{
2016-10-13 00:54:30 +00:00
this.transform._anchorX = value;
this.transform._anchorY = value;
2016-10-12 22:53:39 +00:00
}
},
2016-10-13 00:54:30 +00:00
anchorX: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._anchorX;
2016-10-12 22:53:39 +00:00
},
set: function (value)
{
2016-10-13 00:54:30 +00:00
this.transform._anchorX = value;
2016-10-12 22:53:39 +00:00
}
},
2016-10-13 00:54:30 +00:00
anchorY: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._anchorY;
},
2016-10-12 22:53:39 +00:00
2016-10-13 00:54:30 +00:00
set: function (value)
{
this.transform._anchorY = value;
2016-10-12 22:53:39 +00:00
}
},
2016-10-13 00:54:30 +00:00
pivotX: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._pivotX;
},
2016-10-12 22:53:39 +00:00
2016-10-13 00:54:30 +00:00
set: function (value)
{
this.transform._pivotX = value;
this.transform.dirty = true;
this.transform.updateCache();
2016-10-12 22:53:39 +00:00
}
},
2016-10-13 00:54:30 +00:00
pivotY: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._pivotY;
},
2016-10-12 22:53:39 +00:00
2016-10-13 00:54:30 +00:00
set: function (value)
{
this.transform._pivotY = value;
this.transform.dirty = true;
this.transform.updateCache();
2016-10-12 22:53:39 +00:00
}
},
2016-10-13 00:54:30 +00:00
angle: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
},
2016-10-12 22:53:39 +00:00
2016-10-13 00:54:30 +00:00
set: function (value)
{
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
2016-10-12 22:53:39 +00:00
}
},
2016-10-13 00:54:30 +00:00
rotation: {
2016-10-12 22:53:39 +00:00
enumerable: true,
get: function ()
{
2016-10-13 00:54:30 +00:00
return this.transform._rotation;
},
set: function (value)
{
if (this.transform._rotation === value)
{
return;
}
this.transform._rotation = value;
this.transform.dirty = true;
2016-10-12 22:53:39 +00:00
2016-10-13 00:54:30 +00:00
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;
}
2016-10-12 22:53:39 +00:00
}
}
});