Page 1 of 1

How can I get better at programming menus, textinput, keypressed, and other ui stuff?

Posted: Thu Jun 28, 2018 4:34 am
by xThomas
I started a clone of oregon trail to familiar myself with love. I have not gotten very far. It takes an hour+ for each screen. trail_setup_screen_three took the longest, several hours just adding the switcher between questions. There are unused/redundant variables everywhere, I don't consistently use what I do have, often I'll do things two different ways as I get more familiar with LOVE2d, etc.. At first I thought it'd be best to just finish the game and then figure out what I can do better afterward but i am wasting so much time on menus that I will ask for advice :emo:

Here is the full code so far. 743 lines long

https://pastebin.com/Ap5Vdkxe

Re: How can I get better at programming menus, textinput, keypressed, and other ui stuff?

Posted: Fri Jun 29, 2018 3:13 am
by BruceTheGoose
I would start by separating the contents of that file into different separate files. Very hard to read.

The way I would structure a menu (for example) would look like this:

Code: Select all


-- Menu.lua

Menu = {}

Menu.load = function(self)
 -- Load anything that will be in this menu
end

Menu.update = function(self,dt)
-- Update anything that will be in this menu
end

Menu.draw = function(self)
-- Draw anything that will be in this menu
end

-- main.lua

function love.load()
    require("Menu")
    Menu:load()
end

function love.update(dt)
    Menu:update(dt)
end

function love.draw()
    Menu:draw()
end