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

50 lines
1 KiB
JavaScript
Raw Normal View History

// Origin Component
// Values are normalized, given in the range 0 to 1.
// Display values contain the calculated pixel values.
var Origin = {
originX: 0.5,
originY: 0.5,
2017-08-17 05:26:25 +00:00
// READ ONLY
displayOriginX: 0,
displayOriginY: 0,
setOrigin: function (x, y)
{
if (x === undefined) { x = 0.5; }
if (y === undefined) { y = x; }
this.originX = x;
this.originY = y;
2017-08-17 05:26:25 +00:00
return this.updateOrigin();
},
setDisplayOrigin: function (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
this.displayOriginX = x;
this.displayOriginY = y;
this.originX = (x === 0) ? 0 : this.width / x;
this.originY = (y === 0) ? 0 : this.height / y;
2017-08-17 05:26:25 +00:00
return this;
},
updateOrigin: function ()
{
this.displayOriginX = Math.round(this.originX * this.width);
this.displayOriginY = Math.round(this.originY * this.height);
return this;
}
};
module.exports = Origin;