Page 2 of 2

Re: Organizing your project

Posted: Tue Jun 10, 2014 11:25 am
by easy82
Yeah, for similar reasons I have a table named 'common' that has 'screen' which is a vector.

Code: Select all

local common = require("common")
love.graphics.draw(sprite, common.screen.x - sprite:getWidth(), common.screen.y - sprite:getHeight())
But it would be much easier to call:

Code: Select all

love.graphics.draw(sprite, SCREENX - sprite:getWidth(), SCREENY - sprite:getHeight())

Re: Organizing your project

Posted: Tue Jun 10, 2014 11:36 am
by Roland_Yonaba
Well, we can do something about that:

Code: Select all

local common = require("common")
setmetatable(_G, {__index = common})

-- then you can have this shorter syntax
love.graphics.draw(sprite, screen.x - sprite:getWidth(), screen.y - sprite:getHeight())

Re: Organizing your project

Posted: Tue Jun 10, 2014 12:47 pm
by kikito
I would do this:

Code: Select all

local screen = require("common").screen
love.graphics.draw(sprite, screen.x - sprite:getWidth(), screen.y - sprite:getHeight())
Also, I would call them screen.w & screen.h instead of x and y.

Re: Organizing your project

Posted: Tue Jun 10, 2014 2:59 pm
by easy82
Good ideas! Thank you guys. :)