I have a project that I am working in which the camera follows the center of the player. But, in attempting to debug the game by displaying some variables on the screen, I have ran into a problem. In the following code you can assume that the player and the world are drawn in the function draw_world() and all of the variables I need to display are drawn in draw_debug(). Originally I had the debug values drawn before the world and I noticed that the world overlapped them so I made the debug values be drawn last. However, this still doesn't work. The variables don't stick to the 0, 0 that is in the top left of the window anymore, it is now drawn at 0, 0 in the world. I don't feel like a .love file is necessary for this issue so please don't ask me to provide one. I feel as though I have supplied all of the necessary code to understand the issue at hand.
function love.draw()
love.graphics.translate(-player.x + 400 - (player.w/2), -player.y + 300 - (player.h/2))
draw_world()
love.graphics.translate(0, 0)
draw_debug()
end
Last edited by Dr.Tyler O. on Sun Jun 21, 2015 10:51 am, edited 1 time in total.
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
When this function is called with two numbers, dx, and dy, all the following drawing operations take effect as if their x and y coordinates were x+dx and y+dy.
This change lasts until love.draw() exits or else a love.graphics.pop reverts to a previous love.graphics.push.
Use [wiki]love.graphics.push[/wiki] and [wiki]love.graphics.pop[/wiki] to have a stack of all your transformations and move through them or alternatively use [wiki]love.graphics.origin[/wiki] to reset to the default
for i, person inipairs(everybody) do [tab]ifnot person.obey then person:setObey(true) end end
love.system.openURL(github.com/pablomayobre)
local gamera = require 'gamera'
local player, camera, world
function love.load()
player = ...
world = ...
camera = gamera.new(0,0,world.width, world.height)
end
function love.update(dt)
camera:setPosition(player.x, player.y)
...
end
function love.draw()
-- you could also do cam:draw(draw_world)
camera:draw(function()
draw_world()
end)
draw_debug()
end
Last edited by kikito on Fri Jun 19, 2015 10:25 am, edited 1 time in total.
local gamera = require 'gamera'
local player, camera, world
function love.load()
player = ...
world = ...
camera = gamera.new(0,0,world.width, world.height)
end
function love.update(dt)
cam:setPosition(player.x, player.y)
...
end
function love.draw()
-- you could also do cam:draw(draw_world)
cam:draw(function()
draw_world()
end)
draw_debug()
end