I'm trying to print some text, call 'love.timer.sleep', print some more text, sleep again, print more text etc.
The problem is, instead of sleeping one second and printing the text, it sleeps 3 seconds and then prints all the text at once. How do I fix this?
Need Help With love.timer.sleep
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Need Help With love.timer.sleep
Are you using the print() function, or the love.graphics.print() function?
Re: Need Help With love.timer.sleep
I was using 'love.graphics.print', but after trying just 'print' it works, but prints to the console, which I don't want
Re: Need Help With love.timer.sleep
Any changes on screen are only shown, when "love.graphics.present()" is called. This is done automatically after each "love.draw()". So if you have multiple print statements in one draw, then all the changes will be done, but not be visible.
I recommend against using love.timer.sleep. Please read the other thread to a cleaner solution. There is also a blog-entry about time. Rule of thumb: Only use love.timer.sleep if you really know what you are doing.
Long story short, instead of using sleep, better try it like this:
I recommend against using love.timer.sleep. Please read the other thread to a cleaner solution. There is also a blog-entry about time. Rule of thumb: Only use love.timer.sleep if you really know what you are doing.
Long story short, instead of using sleep, better try it like this:
Code: Select all
function love.load()
timer = 0
end
function love.update(dt)
timer = timer + dt
end
function love.draw()
if timer > 3 then
love.graphics.print('Text after 3 seconds', 100,100)
end
if timer > 6 then
love.graphics.print('Text after 6 seconds', 100,120)
end
end
Check out my blog on gamedev
Re: Need Help With love.timer.sleep
This is how i use timer in a way ...
Hope it helps how to print on screen!
Hope it helps how to print on screen!
Code: Select all
local g=love.graphics
g.setBackgroundColor(100,100,100,255)
local s=0
local time = 05
local white={255,255,255}
local red={255,0,0}
function love.update( dt )
time = time - dt
if time < 0 then
time= 0
s= 1
end
end
function love.draw()
local minutes = math.floor( time / 60 )
local seconds = math.floor( time % 60 )
g.setColor(white)
g.print( string.format("%02d:%02d",minutes,seconds), 400, 300 )
if s==1 then
g.setColor(red)
g.print("Clock Stop", 400, 320 )--print to screen!
end
end
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Need Help With love.timer.sleep
You seem to have created two threads for the same issue. So I'll repost my same reply here:
Use a Timer library like Cron. Don't use love.timer.sleep or os.execute. They don't do what you think they do.
If you use cron, it would be as easy as:
Cron 2.0 thread
Use a Timer library like Cron. Don't use love.timer.sleep or os.execute. They don't do what you think they do.
If you use cron, it would be as easy as:
Code: Select all
message = {
text = "This is my message",
visible = true
}
local seconds = 2 --a second or two
message.timer = cron.after(seconds, function() message.visible = false end)
function yourDrawingFunction()
if message.visible then
love.graphics.print(message.text, 10, 10)
end
end
Re: Need Help With love.timer.sleep
When I use your code, nothing appears on screen.Jasoco wrote:You seem to have created two threads for the same issue. So I'll repost my same reply here:
Use a Timer library like Cron. Don't use love.timer.sleep or os.execute. They don't do what you think they do.
If you use cron, it would be as easy as:Cron 2.0 threadCode: Select all
message = { text = "This is my message", visible = true } local seconds = 2 --a second or two message.timer = cron.after(seconds, function() message.visible = false end) function yourDrawingFunction() if message.visible then love.graphics.print(message.text, 10, 10) end end
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Need Help With love.timer.sleep
It's pseudocode. It's an example. Of course it's not drawing anything because you didn't put anything in love.draw().Kookerus wrote:When I use your code, nothing appears on screen.Jasoco wrote:You seem to have created two threads for the same issue. So I'll repost my same reply here:
Use a Timer library like Cron. Don't use love.timer.sleep or os.execute. They don't do what you think they do.
If you use cron, it would be as easy as:Cron 2.0 threadCode: Select all
message = { text = "This is my message", visible = true } local seconds = 2 --a second or two message.timer = cron.after(seconds, function() message.visible = false end) function yourDrawingFunction() if message.visible then love.graphics.print(message.text, 10, 10) end end
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests