mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 22:52:14 +00:00
Matter.Transform.centerOffsetX
is a new read-only property available on all Matter Game Objects that returns the horizontal offset between the center of the frame and the center of mass. This can be used to allow for accurately mapping texture centers to the body center.
This commit is contained in:
parent
50b511e872
commit
9f012ebf86
1 changed files with 50 additions and 0 deletions
|
@ -187,6 +187,56 @@ var Transform = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the center x offset of the Body this Game Object is using.
|
||||||
|
*
|
||||||
|
* This is calculated by taking the difference between the center of the frame and the center of
|
||||||
|
* the physics body. If set, the `body.render.sprite.xOffset` value is then added to it.
|
||||||
|
*
|
||||||
|
* Use this when setting the Origin of a Physics Game Object post-creation, i.e.:
|
||||||
|
*
|
||||||
|
* `setOrigin(originX + centerOffsetX, originY + centerOffsetY)`
|
||||||
|
*
|
||||||
|
* @name Phaser.Physics.Matter.Components.Transform#centerOffsetX
|
||||||
|
* @type {number}
|
||||||
|
* @readonly
|
||||||
|
* @since 3.22.0
|
||||||
|
*/
|
||||||
|
centerOffsetX: {
|
||||||
|
|
||||||
|
get: function ()
|
||||||
|
{
|
||||||
|
var body = this.body;
|
||||||
|
|
||||||
|
return body.render.sprite.xOffset + ((body.centerOfMass.x - (this.width / 2)) / this.width);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the center y offset of the Body this Game Object is using.
|
||||||
|
*
|
||||||
|
* This is calculated by taking the difference between the center of the frame and the center of
|
||||||
|
* the physics body. If set, the `body.render.sprite.yOffset` value is then added to it.
|
||||||
|
*
|
||||||
|
* Use this when setting the Origin of a Physics Game Object post-creation, i.e.:
|
||||||
|
*
|
||||||
|
* `setOrigin(originX + centerOffsetX, originY + centerOffsetY)`
|
||||||
|
*
|
||||||
|
* @name Phaser.Physics.Matter.Components.Transform#centerOffsetY
|
||||||
|
* @type {number}
|
||||||
|
* @readonly
|
||||||
|
* @since 3.22.0
|
||||||
|
*/
|
||||||
|
centerOffsetY: {
|
||||||
|
|
||||||
|
get: function ()
|
||||||
|
{
|
||||||
|
var body = this.body;
|
||||||
|
|
||||||
|
return body.render.sprite.yOffset + ((body.centerOfMass.y - (this.height / 2)) / this.height);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the position of the physics body along x and y axes. Both the parameters to this function are optional and if not passed any they default to 0.
|
* Sets the position of the physics body along x and y axes. Both the parameters to this function are optional and if not passed any they default to 0.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue