How do I display an image for a longer time?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
teagrumps
Prole
Posts: 6
Joined: Sat Mar 15, 2014 4:19 pm

How do I display an image for a longer time?

Post 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

User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

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

Post 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
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
vynom
Prole
Posts: 28
Joined: Sat Oct 05, 2013 4:42 pm
Location: Teh Interwebz
Contact:

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

Post 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
teagrumps
Prole
Posts: 6
Joined: Sat Mar 15, 2014 4:19 pm

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

Post by teagrumps »

Thanks guys! It works like a charm :D
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests