So I just created an isometric map and added this camera
https://github.com/kikito/gamera
I can zoom in and out but I can't make it move, can't figure what I am doing wrong.
Code: Select all
local gamera = require 'gamera'
local zoom = false
camera_x = 0
camera_y = 0
cam = gamera.new(camera_x,camera_y,1920,1080)
grid_size = 6
screen_width = love.graphics.getWidth()
screen_height = love.graphics.getHeight()
grid_x = (screen_width / 2)
grid_y = (screen_height / 2)
grass = love.graphics.newImage( "grass.png" )
dirt = love.graphics.newImage( "dirt.png" )
block_width = grass:getWidth()
block_height = grass:getHeight()
block_depth = block_height
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
local last_input = "none"
function love.load()
love.window.setMode(0, 0, {fullscreen = true})
end
function love.keypressed(key)
if key == "escape" then
love.event.quit()
elseif key == "left" then
last_input = "left"
camera_x = camera_x - 10
elseif key == "right" then
last_input = "right"
camera_x = camera_x + 10
elseif key == "up" then
last_input = "up"
camera_y = camera_y - 10
elseif key == "down" then
last_input = "down"
camera_y = camera_y + 10
end
end
function love.wheelmoved(x, y)
if y > 0 then
zoom = true
elseif y < 0 then
zoom = false
end
end
function love.update(dt)
cam:setPosition(camera_x, camera_y)
end
function love.draw()
if zoom then
cam:setScale(2.0)
else
cam:setScale(1.0)
end
for x = 1,grid_size do
for y = 1,grid_size do
if grid[x][y] == 1 then
cam:draw(function(l,t,w,h)
love.graphics.draw(grass, grid_x + ((y-x) * (block_width / 2)), grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2))) end)
else -- grid[x][y] == 2
cam:draw(function(l,t,w,h)
love.graphics.draw(dirt, grid_x + ((y-x) * (block_width / 2)), grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2))) end)
end
end
end
love.graphics.print(screen_width .. "x" .. screen_height, 1800, 900)
love.graphics.print("Last pressed key: " .. last_input, 1720, 950)
love.graphics.print("camera: " .. camera_x .. " " .. camera_y, 1800, 1000)
love.graphics.print("camera feedback: " .. cam:getPosition(), 1700, 1040)
end