Hi all,
Defold noob here developing simple 2D game for Android. It’s a simple catch-them-all game where you have to click on flies as they fly around the screen. I am having problem converting touch coordinates to the GOs coordinates.
I am using the generally recommended procedure where one component tracks all clickable GOs and then selects the GOs that were clicked based on the position, similarly as in this example https://github.com/britzl/publicexamples/tree/master/examples/click_game_object.
This works great when the game window has the ratio specified in the game.project, but if I resize the window (or run on a physical device with different screen ratio) the touch coordinates suddenly do not correspond to the GOs position.
I’ve setup a simple demo to test this problem. I have a sprite whose position I set to the touch coordinates (action.x
and action.y
). As you can see on the first image below, with the original window ratio it works just fine, the sprite is right behind the cursor.
However, if I change the screen ratio it suddenly breaks, as seen on the images below.
It seems as though the touch coordinates span the whole window but GO’s coordinates remain the same. I’m using use_fixed_fit_projection
if that makes any difference.
Any ideas what’s happening here? Am I supposed to check the screen ratio and manually transform the screen coordinates to the GO coordinates?
Strangely, this problem doesn’t appear everywhere, e.g. gui.pick_node works as expected.
Thank you for any help!