Page 1 of 1

Help with sleep function

Posted: Wed Mar 13, 2013 1:34 am
by 100sle
I'm sorta new at lua so please don't hate. I'm trying to make an image stay visible for 10 seconds then disappear. Here are the functions I put in...

function love.draw()
love.graphics.setColor( 255, 255, 255, 255 )
love.graphics.draw( imageLevel1, 300, 60, 0, 0.7 ) while true do love.timer.sleep(10).love.graphics.draw( imageLevel1, 300, 60, 0, 0.7 ) while true do imageLevel1 = love.graphics.newImage( "textures/level1.png" )(bool) end end

Re: Help with sleep function

Posted: Wed Mar 13, 2013 1:57 am
by slime
Firstly, use [ code] [/ code] tags to format your code. Secondly, love.timer.sleep will cause the entire program to freeze until it's done sleeping. Thirdly, you should only call newImage once, and use it many times to draw, and lastly your code is doing some weird stuff man. ;)

Here's one way I might make an image stay visible for 10 seconds (there are several similar ways to do this):

Code: Select all

-- love.load will be executed once when the game first starts up.
function love.load()
	imageLevel1 = love.graphics.newImage("textures/level1.png")
	drawtime = 0
end

function love.update(dt)
	drawtime = drawtime + dt
end

function love.draw()
	if drawtime <= 10 then
		love.graphics.draw(imageLevel1, 300, 60)
	end
end