diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index f8d34e6..fdd5b09 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -1,5 +1,5 @@ import EventEmitter from 'eventemitter3'; -import { Rectangle, Transform } from '@pixi/math'; +import { Rectangle, Transform, RAD_TO_DEG, DEG_TO_RAD } from '@pixi/math'; import Bounds from './Bounds'; // _tempDisplayObjectParent = new DisplayObject(); @@ -540,6 +540,7 @@ /** * The rotation of the object in radians. + * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. * * @member {number} */ @@ -554,6 +555,22 @@ } /** + * The angle of the object in degrees. + * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. + * + * @member {number} + */ + get angle() + { + return this.transform.rotation * RAD_TO_DEG; + } + + set angle(value) // eslint-disable-line require-jsdoc + { + this.transform.rotation = value * DEG_TO_RAD; + } + + /** * Indicates if the object is globally visible. * * @member {boolean} diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index f8d34e6..fdd5b09 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -1,5 +1,5 @@ import EventEmitter from 'eventemitter3'; -import { Rectangle, Transform } from '@pixi/math'; +import { Rectangle, Transform, RAD_TO_DEG, DEG_TO_RAD } from '@pixi/math'; import Bounds from './Bounds'; // _tempDisplayObjectParent = new DisplayObject(); @@ -540,6 +540,7 @@ /** * The rotation of the object in radians. + * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. * * @member {number} */ @@ -554,6 +555,22 @@ } /** + * The angle of the object in degrees. + * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. + * + * @member {number} + */ + get angle() + { + return this.transform.rotation * RAD_TO_DEG; + } + + set angle(value) // eslint-disable-line require-jsdoc + { + this.transform.rotation = value * DEG_TO_RAD; + } + + /** * Indicates if the object is globally visible. * * @member {boolean} diff --git a/packages/display/test/DisplayObject.js b/packages/display/test/DisplayObject.js index ca1db96..463c029 100755 --- a/packages/display/test/DisplayObject.js +++ b/packages/display/test/DisplayObject.js @@ -1,4 +1,5 @@ const { DisplayObject, Container } = require('../'); +const { RAD_TO_DEG, DEG_TO_RAD } = require('@pixi/math'); describe('PIXI.DisplayObject', function () { @@ -86,4 +87,25 @@ expect(child.worldVisible).to.be.false; }); }); + + describe('rotation', function () + { + it('rotation and angle are different units of the same transformation', function () + { + const object = new DisplayObject(); + + expect(object.rotation).to.be.equal(0); + expect(object.angle).to.be.equal(0); + + object.rotation = 2; + + expect(object.rotation).to.be.equal(2); + expect(object.angle).to.be.equal(2 * RAD_TO_DEG); + + object.angle = 180; + + expect(object.rotation).to.be.equal(180 * DEG_TO_RAD); + expect(object.angle).to.be.equal(180); + }); + }); });