Page 1 of 1

Cant beat this isometry

Posted: Fri Oct 09, 2015 10:33 pm
by Syberic
So, i have a map made of isometric tiles. I did it just easy and naive like

Code: Select all

    for i = 1,#world do      
      for j = 1,#world do
        tile = world[i][j]
        if tile == '0' then
          love.graphics.draw(grass,(i-1)*32-((j-1))*32,((j-1)*32+(i-1)*32)/2)
        elseif tile == '1' then  
          love.graphics.draw(rocks,(i-1)*32-(j-1)*32,((j-1)*32+(i-1)*32)/2)
        end
      end
    end
but i cant get the exact tile coordinate at any cost. I'm using Vrid's Camera from HUMP, and i'm trying to do this like:

Code: Select all

 x, y = cam:mousepos()
 coordX = math.floor((x-y)/32)
 coordY = math.floor((x+y)/64)

Can someone explain how to do it properly? I'm thowing 100ish paper sheet with plots and maths right now and im totally frustrated.

Re: Cant beat this isometry

Posted: Sat Oct 10, 2015 6:52 am
by ivan
It partially depends on the "tilt" of the tiles.
For a tilt of 30 degrees, take a look at:
http://2dengine.com/doc/gs_isometric.html

If you are looking for a general purpose solution than you have
to investigate 2D affine transformations but it's a lot more complex:
https://code.google.com/p/lua-files/wiki/affine2d