Page 1 of 1

How do I display an image for a longer time?

Posted: Sun Mar 23, 2014 3:56 am
by teagrumps
Hello,

I want to display an image for every state change that takes place. For instance when the player does something right, I might want to display 'Good Job!' on the screen. Currently this is what I have and it works, but the 'Good Job!' image just lasts for a second. I know this is something to do with the update callback but can somebody please tell me how to make the image appear for a little longer time on the screen?
Thanks!

Code: Select all

function love.draw()
if (correct) then
        love.graphics.setColor(255,255,255,255)
        love.graphics.draw( image, goodjob_x, goodjob_y)
        correct = false
    end
end


Re: How do I display an image for a longer time?

Posted: Sun Mar 23, 2014 4:52 am
by HugoBDesigner
You could replace the "correct" value by a number:

Code: Select all

if [something that triggers the correct] then
    correct = [number of seconds]
end
And in love.update you add in this:

Code: Select all

if correct > 0 then
    correct = correct - dt
end
and in love.draw:

Code: Select all

if correct > 0 then
    love.graphics.setColor(255,255,255,255)
    love.graphics.draw( image, goodjob_x, goodjob_y)
    correct = false
end

Re: How do I display an image for a longer time?

Posted: Sun Mar 23, 2014 7:53 am
by vynom
Or take that example, and keep the boolean, just throw in a variable.

Code: Select all

timer = 0
target = 5 --The time in seconds you want to display the image.
correct = true

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

function love.draw()
	if correct and timer <= 5 then
		love.graphics.setColor(255,255,255,255)
		love.graphics.draw( image, goodjob_x, goodjob_y)
	else
		timer = 0
		correct = false
	end
end

Re: How do I display an image for a longer time?

Posted: Sun Mar 23, 2014 3:54 pm
by teagrumps
Thanks guys! It works like a charm :D