phaser/v3/src/gameobjects/components/Transform.js

188 lines
3.2 KiB
JavaScript
Raw Normal View History

var MATH_CONST = require('../../math/const');
var WrapAngle = require('../../math/angle/Wrap');
var WrapAngleDegrees = require('../../math/angle/WrapDegrees');
// global bitmask flag for GameObject.renderMask (used by Scale)
var _FLAG = 4; // 0100
// Transform Component
var Transform = {
// "private" properties
_scaleX: 1,
_scaleY: 1,
_rotation: 0,
_depth: 0,
2017-04-04 22:57:37 +00:00
// public properties / methods
x: 0,
y: 0,
2017-09-15 03:04:51 +00:00
z: 0,
w: 0,
2017-04-04 22:57:37 +00:00
depth: {
2017-04-04 22:57:37 +00:00
get: function ()
{
return this._depth;
2017-03-23 19:51:02 +00:00
},
2017-04-04 22:57:37 +00:00
set: function (value)
{
this.scene.sys.sortChildrenFlag = true;
this._depth = value;
2017-03-23 19:51:02 +00:00
}
2017-04-04 22:57:37 +00:00
2017-03-23 19:51:02 +00:00
},
scaleX: {
get: function ()
{
return this._scaleX;
},
set: function (value)
{
this._scaleX = value;
if (this._scaleX === 0)
{
this.renderFlags &= ~_FLAG;
}
else
{
this.renderFlags |= _FLAG;
}
}
},
scaleY: {
get: function ()
{
return this._scaleY;
},
set: function (value)
{
this._scaleY = value;
if (this._scaleY === 0)
{
this.renderFlags &= ~_FLAG;
}
else
{
this.renderFlags |= _FLAG;
}
}
},
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-09-15 03:04:51 +00:00
setPosition: function (x, y, z, w)
{
2017-03-09 00:41:21 +00:00
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
2017-09-15 03:04:51 +00:00
if (z === undefined) { z = 0; }
if (w === undefined) { w = 0; }
2017-03-09 00:41:21 +00:00
this.x = x;
this.y = y;
2017-09-15 03:04:51 +00:00
this.z = z;
this.w = w;
return this;
},
setRotation: function (radians)
{
2017-03-09 00:41:21 +00:00
if (radians === undefined) { radians = 0; }
this.rotation = radians;
return this;
},
2017-07-13 01:05:44 +00:00
setAngle: function (degrees)
{
if (degrees === undefined) { degrees = 0; }
this.angle = degrees;
return this;
},
setScale: function (x, y)
{
if (x === undefined) { x = 1; }
if (y === undefined) { y = x; }
2017-03-28 23:43:55 +00:00
this.scaleX = x;
this.scaleY = y;
2017-04-04 22:57:37 +00:00
return this;
},
2017-09-15 03:04:51 +00:00
setZ: function (value)
{
if (value === undefined) { value = 0; }
this.z = value;
return this;
},
setW: function (value)
{
if (value === undefined) { value = 0; }
this.w = value;
return this;
},
setDepth: function (value)
2017-04-04 22:57:37 +00:00
{
if (value === undefined) { value = 0; }
this.depth = value;
2017-04-04 22:57:37 +00:00
return this;
}
};
module.exports = Transform;