Camera movement
Posted: Sun Jan 17, 2016 9:53 am
Hello, how do I make the camera follow my player? In my game you can move the airplane with the arrow keys, but I want the camera to follow it. Any help? Thanks
Code: Select all
function love.update(dt)
player:update(dt) -- moves player
cam:lockPosition(player.x, player.y) -- locks the camera on the player
end
Code: Select all
function love.draw()
love.graphics.push()
love.graphics.translate(-player.x, -player.y)
draw_world()
love.graphics.pop()
draw_hud()
end
Code: Select all
-- outside any function:
local plane = {}
-- in love.load:
plane.x = 0
plane.y = 0
plane.graphics = love.graphics.newImage("plane.png")
-- in love.update, you modify the x and y members of plane with keypresses or something
-- in love.draw:
love.graphics.draw(plane.graphics, plane.x, plane.y)
-- Note that this won't move the camera, you'll need to add in one of the above codes from vrld.