snowbillr Posted May 10, 2017 Share Posted May 10, 2017 (edited) Hi everyone! I'm playing around with positioning objects using the alignIn method, and am getting confused about how the bounds of the `world` object are being calculated. Take a look at the codepen here: Aligning the text according to `world.bounds`, `world.getBounds()`, and `world.getLocalBounds()` all ends up with different results. Could somebody help me understand why these calls all return different bounds? (Interesting to note that you can see this happening with the `stage` object too between its `getBounds()` and `getLocalBounds()` methods) EDIT: This is all happening in the `create` method of the State. Not sure if that has anything to do with it either. Edited May 10, 2017 by breed Link to comment Share on other sites More sharing options...
samme Posted May 10, 2017 Share Posted May 10, 2017 All groups have a getBounds() method. It makes a rectangle that covers every visible child of the group, i.e., reaching the leftmost, topmost, rightmost, and bottommost children, wherever they are. It's mostly useful for rendering. world.bounds is a boundary like fence rather than extent. It's a fixed rectangle equal to the game size (if unmodified) or larger (if you've set it yourself). For alignment you probably want world.bounds. Link to comment Share on other sites More sharing options...
samme Posted May 10, 2017 Share Posted May 10, 2017 snowbillr 1 Link to comment Share on other sites More sharing options...
snowbillr Posted May 10, 2017 Author Share Posted May 10, 2017 Ah, I see! So if I call 'getBounds()' on World it will give me back a rectangle covering all its children. But accessing the 'bounds' property of World gives me its "fence" as you called it. Good explanation, thank you! And A+ codepen example! Link to comment Share on other sites More sharing options...
Recommended Posts