General discussion about LÖVE, Lua, game development, puns, and unicorns.
easy82
Party member
Posts: 184 Joined: Thu Apr 18, 2013 10:46 pm
Location: Hungary
Post
by easy82 » Tue Jun 10, 2014 11:25 am
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())
Roland_Yonaba
Inner party member
Posts: 1563 Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:
Post
by Roland_Yonaba » Tue Jun 10, 2014 11:36 am
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())
kikito
Inner party member
Posts: 3153 Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:
Post
by kikito » Tue Jun 10, 2014 12:47 pm
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 .
easy82
Party member
Posts: 184 Joined: Thu Apr 18, 2013 10:46 pm
Location: Hungary
Post
by easy82 » Tue Jun 10, 2014 2:59 pm
Good ideas! Thank you guys.
Users browsing this forum: No registered users and 3 guests