2017-02-23 03:10:48 +00:00
|
|
|
var MATH_CONST = require('../math/const');
|
2017-02-24 01:45:15 +00:00
|
|
|
var WrapAngle = require('../math/angle/Wrap');
|
|
|
|
var WrapAngleDegrees = require('../math/angle/WrapDegrees');
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
// global bitmask flag for GameObject.renderMask (used by Scale)
|
2017-02-23 03:10:48 +00:00
|
|
|
var _FLAG = 4; // 0100
|
|
|
|
|
|
|
|
// Transform Component
|
|
|
|
|
|
|
|
var Transform = {
|
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
// "private" properties
|
|
|
|
_scaleX: 1,
|
|
|
|
_scaleY: 1,
|
|
|
|
_rotation: 0,
|
2017-03-23 19:51:02 +00:00
|
|
|
_z: 0,
|
2017-02-24 01:45:15 +00:00
|
|
|
|
2017-02-23 03:10:48 +00:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
2017-03-23 19:51:02 +00:00
|
|
|
z: {
|
|
|
|
get: function () {
|
|
|
|
return this._z;
|
|
|
|
},
|
|
|
|
set: function (value) {
|
2017-03-24 14:49:54 +00:00
|
|
|
this.state.sortChildrenFlag = true;
|
2017-03-23 19:51:02 +00:00
|
|
|
this._z = value;
|
|
|
|
}
|
|
|
|
},
|
2017-02-23 03:10:48 +00:00
|
|
|
|
|
|
|
scaleX: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
return this._scaleX;
|
2017-02-23 03:10:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
this._scaleX = value;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
if (this._scaleX === 0)
|
2017-02-23 03:10:48 +00:00
|
|
|
{
|
|
|
|
this.renderFlags &= ~_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
scaleY: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
return this._scaleY;
|
2017-02-23 03:10:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
this._scaleY = value;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
if (this._scaleY === 0)
|
2017-02-23 03:10:48 +00:00
|
|
|
{
|
|
|
|
this.renderFlags &= ~_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
angle: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return WrapAngleDegrees(this._rotation * MATH_CONST.RAD_TO_DEG);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
// value is in degrees
|
|
|
|
this.rotation = WrapAngleDegrees(value) * MATH_CONST.DEG_TO_RAD;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
rotation: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._rotation;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
// value is in radians
|
|
|
|
this._rotation = WrapAngle(value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-23 03:10:48 +00:00
|
|
|
setPosition: function (x, y)
|
|
|
|
{
|
2017-03-09 00:41:21 +00:00
|
|
|
if (x === undefined) { x = 0; }
|
2017-02-23 03:10:48 +00:00
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
2017-03-09 00:41:21 +00:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
setRotation: function (radians)
|
|
|
|
{
|
2017-03-09 00:41:21 +00:00
|
|
|
if (radians === undefined) { radians = 0; }
|
|
|
|
|
|
|
|
this.rotation = radians;
|
2017-02-24 01:45:15 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-02-23 03:10:48 +00:00
|
|
|
setScale: function (x, y)
|
|
|
|
{
|
|
|
|
if (x === undefined) { x = 1; }
|
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
2017-03-08 23:49:44 +00:00
|
|
|
this.scaleX = (x ? x : 0.0);
|
|
|
|
this.scaleY = (y ? y : 0.0);
|
2017-02-23 03:10:48 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Transform;
|