I am not sure what translation to use because hump handles the camera with two sets of co-ordinates: one for camera:worldCoords() and one for camera:cameraCoords(), heres an example(use WSAD to move camera. up key + enter for selection of the translation):
Code: Select all
local LightWorld = require "lib"
local lightworld = LightWorld({
drawBackground = drawBackground,
drawForeground = drawForeground,
ambient = {50,50,50},
})
Camera = require "hump.camera"
function love.load()
fthis = 0
this2 = 0
cx = 360
cy = 350
px = 400
py = 300
camera = Camera(0,0)
a = lightworld:newLight(love.mouse.getX(),love.mouse.getY(),155,155,20,200)
b = lightworld:newRectangle(px,py,200,200)
end
function love.draw()
if this2 == 1 then
x,y = camera:worldCoords(10,10)
elseif this2 == 2 then
x,y = camera:cameraCoords(10,10)
elseif this2 == 3 then
local tx,ty = love.graphics.getWidth()/(2*camera.scale), love.graphics.getHeight()/(2*camera.scale)
--the previous method from old light v shadow
x = tx-10
y = ty-10
else
x = 0
y = 0
end
love.graphics.push()
love.graphics.translate(x,y)
-- I am currently on default scale which is 1 so I assume there isn't a need to translate by love.graphics.scale().
lightworld:draw(x,y,1)
love.graphics.pop()
love.graphics.setColor(126,85,98)
love.graphics.rectangle("fill",0,100,300,20)
if fthis == 1 then
love.graphics.setColor(240,200,200)
end
love.graphics.rectangle("fill",0,120,300,20)
love.graphics.setColor(126,85,98)
if fthis == 2 then
love.graphics.setColor(240,200,200)
end
love.graphics.rectangle("fill",0,140,300,20)
love.graphics.setColor(126,85,98)
if fthis == 3 then
love.graphics.setColor(240,200,200)
end
love.graphics.rectangle("fill",0,160,300,20)
love.graphics.setColor(126,85,98)
love.graphics.setColor(255,255,255)
love.graphics.print("The current translation is: "..this2,0,100)
love.graphics.print("1:Set translation to camera:worldCoords()",0,120)
love.graphics.print("2:Set translation to camera:camCoords()",0,140)
love.graphics.print("3:Set translation to light v shadow v1",0,160)
love.graphics.print("camera x:"..camera.x,0,180)
love.graphics.print("camera y:"..camera.y,0,190)
end
function love.keypressed(key)
-- movement and selection of translation
if key == "a" then
px = px + 40
elseif key == "d" then
px = px - 40
end
if key == "w" then
py = py + 40
elseif key == "s" then
py = py - 40
end
if fthis < 4 and fthis > 0 then
if key == "up" then
fthis = fthis + 1
end
if key == "return" then
this2 = fthis
end
else
fthis = 1
end
end
function love.update(dt)
a:setPosition(love.mouse.getX(),love.mouse.getY())
love.window.setTitle(""..love.timer.getFPS())
camera:lookAt(px,py)
end
function lightworld:drawBackground()
love.graphics.setColor(152,150,97)
love.graphics.rectangle("fill",0,0,800,600)
love.graphics.setColor(255,255,255)
camera:attach()
camera:detach()
end
function lightworld:drawForeground()
camera:attach()
--cx2,cy2 = camera:worldCoords(cx,cy)
--b:setPosition(cx2,cy2)
b:setPosition(cx,cy)
love.graphics.setColor(100,100,190)
love.graphics.rectangle("fill",cx,cy,200,200)
love.graphics.setColor(200,200,200)
love.graphics.rectangle("fill",px,py,20,20) -- illustrated the point at which camera looks at
love.graphics.setColor(255,255,255)
camera:detach()
end