Merge pull request #5183 from samme/feature/body-updateFromGameObject

Add Arcade.Body#updateFromGameObject
This commit is contained in:
Richard Davey 2020-07-13 12:39:45 +01:00 committed by GitHub
commit 853feea355
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -903,6 +903,30 @@ var Body = new Class({
this.center.set(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
},
/**
* Updates the Body's `position`, `width`, `height`, and `center` from its Game Object and `offset`.
*
* You don't need to call this for Dynamic Bodies, as it happens automatically during the physics step.
* But you could use it if you have modified the Body offset or Game Object transform and need to immediately
* read the Body's new `position` or `center`.
*
* To resynchronize the Body with its Game Object, use `reset()` instead.
*
* @method Phaser.Physics.Arcade.Body#updateFromGameObject
* @since 3.24.0
*/
updateFromGameObject: function ()
{
this.updateBounds();
var transform = this.transform;
this.position.x = transform.x + transform.scaleX * (this.offset.x - transform.displayOriginX);
this.position.y = transform.y + transform.scaleY * (this.offset.y - transform.displayOriginY);
this.updateCenter();
},
/**
* Prepares the Body for a physics step by resetting the `wasTouching`, `touching` and `blocked` states.
*
@ -961,17 +985,9 @@ var Body = new Class({
this.resetFlags();
}
this.updateBounds();
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.rotation;
this.updateFromGameObject();
this.rotation = this.transform.rotation;
this.preRotation = this.rotation;
if (this.moves)