Hello,
I'm really enjoyed and impressed by the camera.lua features. Good work !
In my game, I need to manage 2 differents things :
- the render part
- the GUI part
The GUI part (see 2) don't need the camera.lua feature, it manage the windows, etc.
In a part of the screen, I show the game (see 1), and I need to be able to move on the map (up/down/right/left) and zoom in/out, like camera.lua do.

- j2h-camera-demo.jpg (193.81 KiB) Viewed 10328 times
My problem was camera.lua change the love function.
So I have made a large number of change. Now my GUI-part and game-part work together.
Now I'm trying to show you my approch, to have a common base and to be able choose if you want that camera.lua do modification in the love functions.
Currently camera.lua :
- create a camera table with camera.love almost like the love structure
- backup some love function in camera.love
- and apply changes on thoses love function
My solution :
- create a camera table with camera.
clove
- copy/backup the whole love functions in camera.clove
- set the camera functions in the camera.clove instead of love
After you can choose to use or not the camera.clove or love functions.
To use the camera features everywhere like the original way
put a
love = camera.clove in the load() function to override every calls.
Code: Select all
function load()
[...]
love.filesystem.require( "camera.lua" )
love = camera.clove
[...]
end
To use the camera features only in a function just put
local love = camera.clove at the begin of your function.
Code: Select all
function draw_ship(x, y, v)
local love = camera.clove
[...]
love.graphics.draw( img, x, y, angle, 0.30);
local before = love.graphics.getFont();
love.graphics.setFont(default_font10);
love.graphics.setLineStyle(love.line_rough)
[...]
love.graphics.setColor(white);
love.graphics.setLineStyle(love.line_rough)
love.graphics.draw( [...] );
love.graphics.setFont( before );
end
Additional informations :
- I also add a simple function named
camera.class:moveOrigin :
Code: Select all
function camera.class:moveOrigin(offsetx, offsety)
local x, y = self:getOrigin()
self:setOrigin(x+offsetx,y+offsety)
end
- I'm don't really use the
camera.lateInit function but it seems running correctly.
- EDIT: I add 2 functions to patch / restore the love functions
Code: Select all
function camera.start()
if not camera.love_backup then
camera.love_backup = love;
end
love = camera.clove;
end
function camera.stop()
if camera.love_backup then
love = camera.love_backup;
camera.love_backup = nil;
end
end
I'm using them to the begin and the end of the render part, so I don't need to change any drawing functions used by the both part.
Note : In camera.stop I don't use
love = camera.love because it override the choice that you can made in the load() by
love = camera.clove
I hope you will anderstand me and try to work together.
Best Regards