Skip to content

Commit

Permalink
StaticBody.setSize will now check to see if the body has a Game Obj…
Browse files Browse the repository at this point in the history
…ect or not, and only call `getCenter` and the frame sizes if it has. This fixes a bug where calling `physics.add.staticBody` would throw an error if you provided a width and height. Fix #6630
  • Loading branch information
photonstorm committed Sep 27, 2023
1 parent f8f48f5 commit 94662cd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/physics/arcade/StaticBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ var StaticBody = new Class({
*/
this.gameObject = (hasGameObject) ? gameObject : undefined;


/**
* A quick-test flag that signifies this is a Body, used in the World collision handler.
*
Expand Down Expand Up @@ -591,14 +590,17 @@ var StaticBody = new Class({

var gameObject = this.gameObject;

if (!width && gameObject.frame)
if (gameObject && gameObject.frame)
{
width = gameObject.frame.realWidth;
}
if (!width)
{
width = gameObject.frame.realWidth;
}

if (!height && gameObject.frame)
{
height = gameObject.frame.realHeight;
if (!height)
{
height = gameObject.frame.realHeight;
}
}

this.world.staticTree.remove(this);
Expand All @@ -609,7 +611,7 @@ var StaticBody = new Class({
this.halfWidth = Math.floor(width / 2);
this.halfHeight = Math.floor(height / 2);

if (center && gameObject.getCenter)
if (center && gameObject && gameObject.getCenter)
{
var ox = gameObject.displayWidth / 2;
var oy = gameObject.displayHeight / 2;
Expand Down

0 comments on commit 94662cd

Please sign in to comment.