Unlimited coordinates system / unlimited map

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.
Post Reply
User avatar
dusoft
Party member
Posts: 510
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Unlimited coordinates system / unlimited map

Post by dusoft »

Hi,

Probably this idea is not new, but I have tried to use out of window (screen resolution) coordinates in love.graphics (e.g. line, rectangle etc.) and it works. (think using negative coordinates that are to the left and top of 0,0 or coordinates to the right/bottom of window width/height)

So I was thinking, since Love2D is able to draw out of visible coordinate system, this could work in coordination with:

Code: Select all

love.graphics.translate
(to move around the map to make desired coordinate window visible)

and

Code: Select all

love.graphics.scale
(to zoom in/out)

as kind of flat map system, right?

Does anyone know, if this has been tried before? And also, if this has any performance impact/consequences?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Unlimited coordinates system / unlimited map

Post by s-ol »

This is exactly how probably 90% of maps are drawn (number made up).

There is a performance impact if you draw a huge, complicated map of course, but in this case you need to optimize whatever way you do it.
If you optimize you can still keep this approach but roughly figure out the range that will end up on your screen and only invest time drawing that.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
dusoft
Party member
Posts: 510
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Unlimited coordinates system / unlimited map

Post by dusoft »

great!

will

Code: Select all

love.graphics.setScissor
be respected impact-wise in terms of not drawing anything else beside the selected rectangle?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Unlimited coordinates system / unlimited map

Post by s-ol »

dusoft wrote: Thu Mar 02, 2017 5:50 am great!

will

Code: Select all

love.graphics.setScissor
be respected impact-wise in terms of not drawing anything else beside the selected rectangle?
no, offscreen contents are scissored automatically afaik (the performance difference will be negligible or nonexistent).

Whats more important is not trying to draw things in the first place, or even better, not even reading the data in Lua.
For example, lets say you're drawing a tilemap:

Code: Select all

love.graphics.translate(-camera.x, -camera.y)
for x=1,1000 do
  for y=1,1000 do
    tiles[x][y]:draw()
  end
end
of course this is not how it usually looks for real, but you get the idea, and probably why you don't want to do that.
Heres a better approach, performance-wise:

Code: Select all

love.graphics.translate(-camera.x, -camera.y)
local width, height = love.graphics.getDimensions()
local sx = math.floor(camera.x / TILEWIDTH)
local sy = math.floor(camera.x / TILEWIDTH)
local ex = math.ceil((camera.x + width) / TILEWIDTH)
local ey = math.ceil((camera.x + height) / TILEWIDTH)
for x=sx,ex do
  for y=sy,ey do
    tiles[x][y]:draw()
  end
end
do you get why and how this works?

Keep in mind that you don't even need to think about this until your game starts to lag, or you are thinking about bringing it to some platform where it lags.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
dusoft
Party member
Posts: 510
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Unlimited coordinates system / unlimited map

Post by dusoft »

Cool, thanks, I understand.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 212 guests