Organizing your project

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
easy82
Party member
Posts: 184
Joined: Thu Apr 18, 2013 10:46 pm
Location: Hungary

Re: Organizing your project

Post 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())
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Organizing your project

Post 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())
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Organizing your project

Post 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.
Last edited by kikito on Tue Jun 10, 2014 3:07 pm, edited 1 time in total.
When I write def I mean function.
User avatar
easy82
Party member
Posts: 184
Joined: Thu Apr 18, 2013 10:46 pm
Location: Hungary

Re: Organizing your project

Post by easy82 »

Good ideas! Thank you guys. :)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests