TL;DR:
action.x and action.y are the action positions in virtual coordinates, which are needed to detect clicks in the GUI using gui.pick_node(). Most likely, you don’t need them for any manual calculations.
Use action.screen_x and action.screen_y instead.
Full Explanation
The engine does the following steps to get these values:
- Raw Input: Defold receives mouse/touch coordinates in actual screen pixels (where the user clicked).
- Virtual Scaling: These pixel coordinates are scaled to match your game’s virtual resolution (set in
game.projectunderdisplay.widthanddisplay.height). - Pixel Centering: A 0.5 pixel offset ensures coordinates point to the center of pixels rather than their corners.
What This Means for You
action.xandaction.yare always in your game’s virtual coordinate space.- If your game is set to 960x640 virtual resolution, coordinates will be
0–960horizontally and0–640vertically. - This works regardless of the actual screen size — a 1920x1080 screen or a 480x320 screen will both give you the same virtual coordinates.
What Should You Use Then?
It’s better to use action.screen_x and action.screen_y for everything you want to calculate yourself.
Screen space is a universal space that can be used to convert different coordinates between different systems. For example:
- From world to GUI
- From GUI to world (depends on camera setup)
- From a GUI node with one scale setting to a GUI node with another
Helpful Functions for Screen-Space Conversions
We don’t have such functions for go because they highly depend on the camera/render_script setup. (We plan to add them under the camera.* or go.* namespaces.)
In the meantime, here are examples of helper functions you can use: