Cant beat this isometry

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
Syberic
Prole
Posts: 6
Joined: Fri Oct 09, 2015 10:26 pm

Cant beat this isometry

Post 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.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Cant beat this isometry

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest