I would like to add my two cents to this.
All the techniques said above are valid. But you might find this one simpler to grasp, unless I totally missed what you are asking for.
So, whether your game is tiled based or not, this one works. First, let's say you have the size of the world:
Code: Select all
local worldWidth, worldHeight = 1000, 1000
For simplicity, I will suppose that the location (0,0), i.e the upper-left pixel on the screen (the graphics origin in Löve, actually) is the origin of the world.
That means that any entity can freely move between 0 and 1000 (in both x and y axis).
To render the minimap, you will have to define some other parameters: the dimensions of the minimap window (in both width and height), and also the coordinates where it will be drawn (i'll choose here the lower right corner of the screen):
Code: Select all
local minimapWidth, minimapHeight = 100, 100
local minimapX = love.graphics.getWidth() - minimapWidth
local minimapY = love.graphics.getHeight() - minimapHeight
From that, you can define two functions translate coordinates from the real world to minimap coordinates, and vice versa.
Code: Select all
-- This translates the (x,y) coordinates in the world to (mx, my) coordinates
-- in the minimap. Note that mx, my are relative to the origin of the minimap.
-- so the object should be rendered at minimapX + mx, minimapY + my
local function worldToMinimap(x, y)
local mX = x * (minimapWidth / worldWidth)
local mY = y * (minimapHeight / worldHeight)
return mX, mY
end
-- This translates the (mx,my) coordinates in the minimap to (x,y) coordinates
-- in the world. Note that mx, my given to the function should be relative origin of the minimap.
local function minimapToWorld(mx, my)
local x = mx * (worldWidth / minimapWidth)
local y = my * (worldHeight / minimapHeight)
return x, y
end
This is simple to setup, but it has its limitations. For instance, if your world scales (up or down),
it becomes quite tricky (but not impossible) to manage. The technique The great Germanunkol suggested before is more feature complete and elegant.
You can also use The great Kikito's
gamera, I suspect you can setup a minimap easily with it.
Feel free to ask any questions in case you want more details on this.
Hope this helps.
Edit: well, this is quite similar to Germanunkol's suggestion, except that it renders straight to the screen, and does not make use of meshes
![Smile :)](./images/smilies/ms-smile.png)