So I recently wanted to confine a game object to the screen, i.e. so that it is not able to leave it. The way that I know how to do this is to simply get the width and height of the screen and compare it with the object’s position to set the position accordingly. In addition, one should get half the size of the game object (I do that by getting the size of the sprite multiplied by the game objects scale factor) and add that to their calculations so that the object is fully on the screen and not only half of it. Which is where my problem takes place.
The objects that I want to confine are created through a factory and can have an arbitrary rotation applied to them. As soon as the applied rotation is not zero the confining method is less effective. And I’m sure this is the case because I’m only capable of getting the object’s width and height through the sprite size, but this size does not represent the correct width and height of the game object after applying a rotation to it. You could say I’m looking for a way to acquire width and height as a variable from a game object by relying on something like a bounding box rather than a sprite. Is there some way to achieve this in Defold or an alternative?