mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
Change arguments to StaticBody#setSize
`center` replaces `offsetX`, `offsetY`
This commit is contained in:
parent
77859b1cdf
commit
7bba56be16
1 changed files with 17 additions and 7 deletions
|
@ -520,15 +520,13 @@ var StaticBody = new Class({
|
||||||
*
|
*
|
||||||
* @param {integer} [width] - The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width.
|
* @param {integer} [width] - The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width.
|
||||||
* @param {integer} [height] - The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height.
|
* @param {integer} [height] - The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height.
|
||||||
* @param {number} [offsetX] - The horizontal offset of the Body from the Game Object's center.
|
* @param {boolean} [center=true] - Modify the Body's `offset`, placing the Body's center on its Game Object's center. Only works if the Game Object has the `getCenter` method.
|
||||||
* @param {number} [offsetY] - The vertical offset of the Body from the Game Object's center.
|
|
||||||
*
|
*
|
||||||
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
||||||
*/
|
*/
|
||||||
setSize: function (width, height, offsetX, offsetY)
|
setSize: function (width, height, center)
|
||||||
{
|
{
|
||||||
if (offsetX === undefined) { offsetX = this.offset.x; }
|
if (center === undefined) { center = true; }
|
||||||
if (offsetY === undefined) { offsetY = this.offset.y; }
|
|
||||||
|
|
||||||
var gameObject = this.gameObject;
|
var gameObject = this.gameObject;
|
||||||
|
|
||||||
|
@ -550,7 +548,19 @@ var StaticBody = new Class({
|
||||||
this.halfWidth = Math.floor(width / 2);
|
this.halfWidth = Math.floor(width / 2);
|
||||||
this.halfHeight = Math.floor(height / 2);
|
this.halfHeight = Math.floor(height / 2);
|
||||||
|
|
||||||
this.offset.set(offsetX, offsetY);
|
if (center && gameObject.getCenter)
|
||||||
|
{
|
||||||
|
var ox = gameObject.displayWidth / 2;
|
||||||
|
var oy = gameObject.displayHeight / 2;
|
||||||
|
|
||||||
|
this.position.x -= this.offset.x;
|
||||||
|
this.position.y -= this.offset.y;
|
||||||
|
|
||||||
|
this.offset.set(ox - this.halfWidth, oy - this.halfHeight);
|
||||||
|
|
||||||
|
this.position.x += this.offset.x;
|
||||||
|
this.position.y += this.offset.y;
|
||||||
|
}
|
||||||
|
|
||||||
this.updateCenter();
|
this.updateCenter();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue