mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
Merge pull request #5183 from samme/feature/body-updateFromGameObject
Add Arcade.Body#updateFromGameObject
This commit is contained in:
commit
853feea355
1 changed files with 26 additions and 10 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue