World coordinates vs screen coordinates


when calling an expression like “object.X()” we can read the position X of the object in its layer, and depending on the camera position, it is different from the coordinates on the screen.

what about an expression to read the SCREEN COORDINATES, maybe can be useful.

many thanks,


1 Like

I don’t know but maybe you can use DifferenceBetweenTwoAngles(ScreenWIdth()/2, Object.X()) and same for Y

1 Like

I don’t think there is a feature like this for any other game engine.

Well, just to say, Darkbasic Pro can convert a point of a 3d world to a screen x and y coord of a specified camera.

my intended use: i’ve many levels, objects, zoom and unzoom situations. Over all this madness i’ve a not moving level, with an user interface, displaying data and maps. i would like to place near some objects a badge, with some info, but it must be always of the same size and without the layer’s effect i chosed.

so, if i can read the relative screen x and y position of objects, i can place those info in the user interface level.

i don’t know about the comand “DifferenceBetweenTwoAngles(ScreenWidth()/2, Object.X())” , i will check.

regards, Ermes

and thanks.

1 Like

To get the screen co-ordinates, get the difference between the the camera position and the object position, and take into account the screen width.

I think something like object.X() - Camera.X() + (ScreenWidth() * 0.5).

Don’t check. Angle differences have nothing to do with positional offesets

1 Like

Interesting, like touch position

1 Like

good. but what about zoomed cameras???

must have a value (empiric value * zoom value) to use for multiply/divide the formula you wrote.

something like that, but with objects instead of fingers.

You have to subtract camera position to object position and calculate the distance using zoom proportion
Something like
1:zoom=(camera position- half camera size) - object position: screen position

… nice. we can get all we want with tons of formula, but what a simple command to do this? :slight_smile:

btw, there is a command to know distance between two objects/points? need to use pitagora all the way?

edit: i’ve to go, see you laters my friends.

That would only affect the screen width/height calculation and may only require those values be divided by the zoom amount.

Not that I’m aware of in GDevelop. But you could create a function and call that every time, rather than retyping the formula.



It’s available for conditions. In the condition popup, you need to select the first object, then this command then the second object.


You can write the extension and share it with this community.


uhmm for distance… i found this, a f(x): DistanceBetweenPosition(number, number, number, number)

i think it is something like “distance=sqrt((x1-x2)^2+(y1-y2)^2)”

so i can know the distance, non compare numbers to it.



Yes, if you are using points and don’t have the objects.

If it’s two objects you can have it easier by doing Object1.Distance(Object2) instead :wink:

1 Like

yes, much better. i need this for scale a line, as a “Laser”, between player and enemy.