Page 1 of 1

love.timer.sleep() dosn't let images load!

Posted: Sun May 12, 2013 6:45 am
by JamesWillson
Hi, a quick question,

I am trying to create a splash screen, and this is the code I have:


splash1 = love.graphics.newImage( "/images/splash1.jpg" )
love.graphics.setColor(255,255,255)
love.graphics.draw(splash1, 0, 0)
love.timer.sleep(2)
splash2 = love.graphics.newImage( "/images/splash2.jpg" )
love.graphics.setColor(255,255,255)
love.graphics.draw(splash2, 0, 0)
love.timer.sleep(2)
splash3 = love.graphics.newImage( "/images/splash3.jpg" )
love.graphics.setColor(255,255,255)
love.graphics.draw(splash3, 0, 0)
love.timer.sleep(2)

However, when I try and do this (in the love.load() function,) it just dosn't show the images at all! It'll wait the time, but just dosn't show them! Any help? Thank you so much!

Re: love.timer.sleep() dosn't let images load!

Posted: Sun May 12, 2013 6:59 am
by Boolsheet
We discourage the use of love.timer.sleep like that because the execution of the program gets stopped completely and it just sits there for that amount of time. Your code can't react to user input and the user may get confused why it locked up on him.

Instead, try to use states that represent those splash screens. Setup a variable that acts as a timer and once reaches the two second limit, it switches to the next state.


The reason you're not seeing anything is because most graphics drivers will support double buffering and a buffer switch is necessary to display the frame you have drawn. This is exposed with love.graphics.present. Call it after the draw and before the sleep and it should show up as expected. This function is called in the default love.run callback in case you're wondering why it worked with the main loop.