diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index 5ad789870..e4b354dc2 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -7,8 +7,10 @@ var CircleContains = require('../../geom/circle/Contains'); var Class = require('../../utils/Class'); var CONST = require('./const'); +var RadToDeg = require('../../math/RadToDeg'); var Rectangle = require('../../geom/rectangle/Rectangle'); var RectangleContains = require('../../geom/rectangle/Contains'); +var TransformMatrix = require('../../gameobjects/components/TransformMatrix'); var Vector2 = require('../../math/Vector2'); /** @@ -66,6 +68,23 @@ var Body = new Class({ */ this.gameObject = gameObject; + /** + * [description] + * + * @name Phaser.Physics.Arcade.Body#transform + * @type {object} + * @since 3.4.0 + */ + this.transform = { + x: gameObject.x, + y: gameObject.y, + rotation: gameObject.angle, + scaleX: gameObject.scaleX, + scaleY: gameObject.scaleY, + displayOriginX: gameObject.displayOriginX, + displayOriginY: gameObject.displayOriginY + }; + /** * [description] * @@ -709,6 +728,8 @@ var Body = new Class({ * @since 3.0.0 */ this._bounds = new Rectangle(); + + this._tempMatrix = new TransformMatrix(); }, /** @@ -721,6 +742,29 @@ var Body = new Class({ { var sprite = this.gameObject; + // Container? + + var transform = this.transform; + + if (sprite.parentContainer) + { + var matrix = sprite.getWorldTransformMatrix(this._tempMatrix); + + transform.x = matrix.tx; + transform.y = matrix.ty; + transform.rotation = RadToDeg(matrix.rotation); + transform.scaleX = matrix.scaleX; + transform.scaleY = matrix.scaleY; + } + else + { + transform.x = sprite.x; + transform.y = sprite.y; + transform.rotation = sprite.angle; + transform.scaleX = sprite.scaleX; + transform.scaleY = sprite.scaleY; + } + if (this.syncBounds) { var b = sprite.getBounds(this._bounds); @@ -734,8 +778,8 @@ var Body = new Class({ } else { - var asx = Math.abs(sprite.scaleX); - var asy = Math.abs(sprite.scaleY); + var asx = Math.abs(transform.scaleX); + var asy = Math.abs(transform.scaleY); if (asx !== this._sx || asy !== this._sy) { @@ -803,16 +847,17 @@ var Body = new Class({ this.embedded = false; + // Updates the transform values this.updateBounds(); - var sprite = this.gameObject; + var sprite = this.transform; this.position.x = sprite.x + sprite.scaleX * (this.offset.x - sprite.displayOriginX); this.position.y = sprite.y + sprite.scaleY * (this.offset.y - sprite.displayOriginY); this.updateCenter(); - this.rotation = sprite.angle; + this.rotation = sprite.rotation; this.preRotation = this.rotation; @@ -918,6 +963,9 @@ var Body = new Class({ } } + // this.transform.x += this._dx; + // this.transform.y += this._dy; + this.gameObject.x += this._dx; this.gameObject.y += this._dy;