Basic question on how to move the camera around. Using hump camera.
Here is what I have so far. Pressing "d" or "s" doesn't move anything. Also, cam doesn't seem to want to "start" at coordinates 100, 100 for some reason, but I don't get an error.
function love.load()
Camera = require "lib.camera"
viewx = 100; viewy = 100
cam = Camera(viewx, viewy, 0)
end
function love.keypressed(key)
if key == "d" then
cam:move(250, 250)
if key == "s" then
viewx = viewx + 1
end
end
function love.update(dt)
local dx, dy = viewx - cam.x, viewy - cam.y
cam:move(dx/2, dy/2)
end
Sorry, just a typo when I was writing out the question. In my code it's correct. I can run the game, get no error messages, but pressing the keys does nothing.
function love.update(dt)
local dx, dy = viewx - cam.x, viewy - cam.y
cam:move(dx/2, dy/2)
end
you kinda lock your camera to this point (it automatically moves with the viewx, viewy positions). This is why your key input does not work.
To check the position the camera starts you can print out the camera position in your draw function. I guess it will be at 100, 100 when removing the code in your update function.
I'm printing out the camera coordinates like you suggested, and they seem to change with the s key. But nothing on the screen moves. I feel like I'm missing some basic thing.
Here's the code, and I'll attach a .love which illustrates the issue
But, you should work out structural order of your lua files, the main.lua file should just be calling everything and updating the game not much else "I do have screen resolution" going on in my main lua file but when it comes time for my RPG KIT release it'll be in it's own lua file.