[Solved] Draw before update?
Posted: Mon Mar 14, 2022 6:15 am
Got myself in a pickle here. Go easy, I'm still wearing my noob badge
I have a few game "states" that I'm using ("INTRO", "MENU", "GAME"). I am aware of state machines and such, but for this project I am not using any external libs other then to recursively print tables for troubleshooting.
For each, i have something.lua, each having an update and draw function. For example.
Now, in main.lua, I'm doing something like this for update and draw:
I want to point out that each scene works fine when I bypass the if logic and just force the scene i want.
However, when I transition I am running into trouble. Here's what happens,
Intro:update runs as expected until there is nothing left to do. It then transitions:
Great, on the next iteration we'll go to the MENU. However, we end up hitting Menu:draw before Menu:update runs. Fail. light blue screen of death.
I tried to make a "toggle switch" to bypass that first run.
So, my return of course is only breaking me out of my if rather then the function making the check useless. Yup, I get it; my bad. But now what? Any thoughts here how to break out of draw(), or other ideas? I could throw my menuState.drawAction() in an else and call it a day, but i feel this is getting more and more hacky by the second.
I have a few game "states" that I'm using ("INTRO", "MENU", "GAME"). I am aware of state machines and such, but for this project I am not using any external libs other then to recursively print tables for troubleshooting.
For each, i have something.lua, each having an update and draw function. For example.
Code: Select all
function Menu:update(speedAdjustment)
...
end
Code: Select all
function love.update(dt)
if Settings.GlobalStates.activeScene == 'GAME' then
Input:update(dt * Settings.gameSpeed)
Ball:update(dt * Settings.gameSpeed)
elseif Settings.GlobalStates.activeScene == 'INTRO' then
Intro:update(dt)
elseif Settings.GlobalStates.activeScene == 'MENU' then
Menu:update(dt)
end
end
However, when I transition I am running into trouble. Here's what happens,
Intro:update runs as expected until there is nothing left to do. It then transitions:
Code: Select all
-- in Intro:update
Settings.GlobalStates.activeScene = 'MENU'
I tried to make a "toggle switch" to bypass that first run.
Code: Select all
function Menu:draw()
-- (updateHasRun) and true or return
if (updateHasRun ~= true) then
print('nah dont do it')
return
end
menuState.drawAction()
end