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

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
JamesWillson
Prole
Posts: 5
Joined: Sun May 12, 2013 6:41 am

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

Post 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!
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

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

Post 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.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests