[SOLVED] Hump.gamestate - switch inside update problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
bloodcraft
Prole
Posts: 6
Joined: Sat Sep 17, 2016 9:50 am

[SOLVED] Hump.gamestate - switch inside update problem

Post 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

Last edited by bloodcraft on Sat Sep 17, 2016 12:33 pm, edited 1 time in total.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Hump.gamestate - switch inside update problem

Post by MadByte »

I can't reproduce your problem, everything works as expected for me.
bloodcraft
Prole
Posts: 6
Joined: Sat Sep 17, 2016 9:50 am

Re: Hump.gamestate - switch inside update problem

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Hump.gamestate - switch inside update problem

Post 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.
bloodcraft
Prole
Posts: 6
Joined: Sat Sep 17, 2016 9:50 am

Re: Hump.gamestate - switch inside update problem

Post 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
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests