A few questions from a Lua/Love2D newbie.
Posted: Mon Dec 15, 2014 11:38 pm
Hi there guys!
Firstly, although I would not consider myself a 'professional' coder (more of an occasional 'hobby programmer'), I have worked on and off for nearly 4 years developing applications and programs in both Java and ActionScript 2/3 (Flash). I first discovered Love2D last year, but never really looked into it further. I saw it pop up again while doing some reading online and have decided to have a crack at learning both Love2D and Lua at the same time.
In a few days, I feel I have already gotten to grips with Lua a fair bit, however there are a few general questions regarding Lua and Love2D I would like to ask and hopefully you guys can steer me in the right direction .
Q1: What is the best approach to OOP with Lua/Love2D?
There are no classes in Lua (as far as I can tell), so everything seems to pretty much be a table (which definitely has it's perks for many things!). How should I handle many instances of the same object? Just generate an table with the same functions each time? If so, how do I inherit other tables methods?
Q2: Saving/Loading data with Love2D?
I'm currently playing around with a small application which attempts to predict long-term market trends based off lots of data (*yawn*).
Parsing in this data from a file was fairly simple, but once the love2d app closes, I have to re-parse the data again when I run it.
How can I save this data and reload it in a Lua form (serialised) without repeating the parsing procedure?
Can I just save the data in raw Lua files and require() them in if they exist next time?
Q3: General love.graphics questions
I feel that calling love.graphics.setColor() and love.graphics.setFont() hundreds of time each love.draw() is a bit crazy. Is it ok to do that? Although I get constant 60FPS doing both functions say 200 times each draw() call, is it acceptable? If not, how can I minimise these calls if I do need to change colours a lot? Is drawing to canvases faster?
Finally, any general tips for a Java/ActionScript programmer leaping head-first into Love2D/Lua?
Firstly, although I would not consider myself a 'professional' coder (more of an occasional 'hobby programmer'), I have worked on and off for nearly 4 years developing applications and programs in both Java and ActionScript 2/3 (Flash). I first discovered Love2D last year, but never really looked into it further. I saw it pop up again while doing some reading online and have decided to have a crack at learning both Love2D and Lua at the same time.
In a few days, I feel I have already gotten to grips with Lua a fair bit, however there are a few general questions regarding Lua and Love2D I would like to ask and hopefully you guys can steer me in the right direction .
Q1: What is the best approach to OOP with Lua/Love2D?
There are no classes in Lua (as far as I can tell), so everything seems to pretty much be a table (which definitely has it's perks for many things!). How should I handle many instances of the same object? Just generate an table with the same functions each time? If so, how do I inherit other tables methods?
Q2: Saving/Loading data with Love2D?
I'm currently playing around with a small application which attempts to predict long-term market trends based off lots of data (*yawn*).
Parsing in this data from a file was fairly simple, but once the love2d app closes, I have to re-parse the data again when I run it.
How can I save this data and reload it in a Lua form (serialised) without repeating the parsing procedure?
Can I just save the data in raw Lua files and require() them in if they exist next time?
Q3: General love.graphics questions
I feel that calling love.graphics.setColor() and love.graphics.setFont() hundreds of time each love.draw() is a bit crazy. Is it ok to do that? Although I get constant 60FPS doing both functions say 200 times each draw() call, is it acceptable? If not, how can I minimise these calls if I do need to change colours a lot? Is drawing to canvases faster?
Finally, any general tips for a Java/ActionScript programmer leaping head-first into Love2D/Lua?