Page 1 of 1

[SOLVED] Hump.gamestate - switch inside update problem

Posted: Sat Sep 17, 2016 10:14 am
by bloodcraft
Hi. I noticed that when I call Gamestate.switch(nextGamestate) from another gamestate's update(dt), the screen blinks as if empty background is drawn for a single frame. If I call switch from somewhere else like keypressed, there is no problem. Can you please help me to get rid of this annoying blinking?

Here is example code:

Code: Select all


Gamestate = require('lib.hump.gamestate')

local state1 = {}
local state2 = {}

local time = 0

function love.load()
    love.graphics.setBackgroundColor(0,255,0)
    Gamestate.registerEvents()
    Gamestate.switch(state1)
end

function state1:update(dt)
  time = time + dt
  if time > 3 then
    time = 0
    Gamestate.switch(state2)
  end
end

function state1:draw()
  love.graphics.setColor(255,0,0)
  love.graphics.rectangle('fill',0,0,2000,2000)
end

function state2:draw()
  love.graphics.setColor(255,0,0)
  love.graphics.rectangle('fill',0,0,2000,2000)
end

function state2:keypressed()
  Gamestate.switch(state1)
end


Re: Hump.gamestate - switch inside update problem

Posted: Sat Sep 17, 2016 11:04 am
by MadByte
I can't reproduce your problem, everything works as expected for me.

Re: Hump.gamestate - switch inside update problem

Posted: Sat Sep 17, 2016 11:21 am
by bloodcraft
You din't see a flash of green color after 3 seconds? That's weird. I just tried to run it on a different computer and made sure I have most recent versions of löve and hump but it didn't help.

Re: Hump.gamestate - switch inside update problem

Posted: Sat Sep 17, 2016 12:14 pm
by bartbes
It's the one thing I hate about hump.gamestate. After switching, no events are forwarded until the next update[source]. You can patch it out, or delay switching. If you do patch it out, you will run into situations where draw will run before update, but if your state is well-designed, that shouldn't be a problem.

Re: Hump.gamestate - switch inside update problem

Posted: Sat Sep 17, 2016 12:31 pm
by bloodcraft
Thank you bartbes! All I had to do was to call love.update() after entering new gamestate.

Like this in my example above:

Code: Select all

function state2:enter()
  love.update()
end

Re: [SOLVED] Hump.gamestate - switch inside update problem

Posted: Sat Sep 17, 2016 2:15 pm
by zorg
Mind you all, this behaviour didn't exist previously, but was patched in after an issue was raised, wherein vrld deemed it the correct course of action.

My solution was to use an older version that did not include this fix.