Iso drawing help
Posted: Sun Apr 07, 2019 12:40 pm
Hi
I'm new to Love coding and read a isometric tutorial. (Link here https://love2d.org/wiki/Tutorial:Isometric_Graphics) I got the code working (I think) and now want to change the dirt image to house image. But when I modify the code it doesn't look right anymore, the houses are way off from where they should be. Here's screenshot: https://love2d.org/imgmirrur/VSFyUWh.png
And here's my code ( Most of my changes are in draw() )
can some one help to get it working?
thx!
I'm new to Love coding and read a isometric tutorial. (Link here https://love2d.org/wiki/Tutorial:Isometric_Graphics) I got the code working (I think) and now want to change the dirt image to house image. But when I modify the code it doesn't look right anymore, the houses are way off from where they should be. Here's screenshot: https://love2d.org/imgmirrur/VSFyUWh.png
And here's my code ( Most of my changes are in draw() )
Code: Select all
function love.load()
grass = love.graphics.newImage("grass.png")
dirt = love.graphics.newImage("dirt.png")
house = love.graphics.newImage("house.png")
block_width = grass:getWidth()
block_height = grass:getHeight()
block_depth = block_height / 2
grid_size = 20
grid = {}
for x = 1,grid_size do
grid[x] = {}
for y = 1,grid_size do
grid[x][y] = 1
end
end
grid[2][4] = 2
grid[6][5] = 2
grid_x = 350
grid_y = 250
end
function love.draw()
for x = 1,grid_size do
for y = 1,grid_size do
if grid[x][y] == 1 then
love.graphics.draw(grass,
grid_x + ((y-x) * (block_width / 2)),
grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth)
else -- grid[x][y] == 2
bd = house:getHeight() / 2
bw = house:getWidth()
love.graphics.draw(house,
grid_x + ((y-x) * (bw / 2)),
grid_y + ((x+y) * (bd / 2)) - (bd * (grid_size / 2)) - bd)
end
end
end
end
thx!