## Transforming coordinates to screen coordinates

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
ElmuKelmuZ
Prole
Posts: 14
Joined: Sat Sep 01, 2012 7:43 pm

### Transforming coordinates to screen coordinates

I have my own Vector2-pseudoclass I use for positions and sizes of objects (https://gist.github.com/Elmuti/a26cdf288752698a58d0).

I should obviously have this coordinate system separate from rendering,so i need to transform these v2(x, y) -coordinates to screen coordinates that I can use

Code: Select all

love.graphics.draw
with.

I'm new to games, so if anyone could explain to me how I could achieve this transformation I'd really appreciate it

micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

### Re: Transforming coordinates to screen coordinates

The simplest solution is to go for a constant scaling factor. Let's call the coordinates you handle with your vectors world coordinates and the coordinates on screen screen coordinates. You can transform between the two by simple multiplication:

Code: Select all

function sx,sy = worldToScreen(wx,wy)
sx = wx * scaleX
sy = wy * scaleY
end

function wx,wy = screenToWorld(sx,sy)
wx = sx / scaleX
wy = sy / scaleY
end
The variables scaleX and scaleY tell you how many pixels one world-coordinate-unit is. For example if you are using 32-by-32 pixel tiles, then scaleX and scaleY would be 32.

The next step would be scrolling. You could incorporate this into the two functions above by adding an offset. However, I suggest you use one of the camera libraries available (for example gamera)

### Who is online

Users browsing this forum: No registered users and 24 guests