How to make a Isometric Projection in Löve2D?

85 views Asked by At

I'm trying to make a Isometric Projection in Löve2D, but the code to do the positioning of the isometric cubes is not positioning them correctly. My objective is reach something like this:

Example:

but when running the code, I got something like this:

in this case, Block1 is in (0,0,0) and Block2("The Block") is in (0,0,1) in this case, Block1 is in (0,0,0) and Block2("The Block") is in (1,0,0)

My code:

-- This Class only stores the position of the block and a string variable to differentiate from each other when printing
local Block = require("engine/block")

function love.load()
    love.graphics.setBackgroundColor(189/255, 147/255, 249/255)
    love.graphics.setDefaultFilter("nearest","nearest")

    image = love.graphics.newImage("planning/IsometricTile.png")
    blocks = {}
    table.insert(blocks, Block({0,0,0}, ""))
    table.insert(blocks, Block({0,0,0}, "The Block"))
end

function love.draw()
    for _, block in pairs(blocks) do
        x,y = Iso(block.x,block.y,block.z)
        love.graphics.draw(image,100+x,100+y)
        love.graphics.print(block.type,100+x,100+y)
    end
end

function Iso(x,y,z)
    iso_x = (x-y) * (32/2)
    iso_y = (x+y) * (32/2) - z * (32/2)
    return iso_x, iso_y
end

*extra question: how to make the draw code draw in correct order?

0

There are 0 answers