Help with sleep function

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
100sle
Prole
Posts: 2
Joined: Sun Mar 10, 2013 2:04 am

Help with sleep function

Post 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
User avatar
slime
Solid Snayke
Posts: 3133
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Help with sleep function

Post 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
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 63 guests