Jump to content

getBounds() sucks


ForgeableSum
 Share

Recommended Posts

There, I said it. 

 

How often do you want to get a representation of one of your game images or sprites as a rectangle so you can perform stuff like intersection checks? Very often. But the rectangle should be relative to the world, amiright? That's what I don't understand about getBounds(). The x/y values of the rectangle are not relative to the world.. are they relative to the parent? what the hell is worldTransform? I have no clue. I figured it out several times before but I've since forgotten - because it's so counterintuitive, what getBounds does.

 

The end result is that getBounds returns a rectangle with x/y not relative to the game world. I think this is pretty silly. I had to make my own function for getting/updating bounds:

 

function getManualBounds(object) {
    if (object.manualBounds == undefined) {
        object.manualBounds = new Phaser.Rectangle(object.x - object.offsetX, object.y - object.offsetY, object.width, object.height);
    } else {
        object.manualBounds.x = object.x - object.offsetX;
        object.manualBounds.y = object.y - object.offsetY;
    }
    return object.manualBounds;
}

 

 

Is anyone else in the same boat?

Why is getBounds so useless? what is "worldTransform"?

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...