Very simple question on "Wait".
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Very simple question on "Wait".
I used to program on a game called Roblox(Not very good engine) and it used Lua. It had something called "Wait()" It would wait for the amount of seconds in the parameters. Does LOVE have anything like this? Say I wanted to make a box, then one more, then another all one second apart. could I do this with a loop that runs every second?
Re: Very simple question on "Wait".
Yes, LÖVE has love.timer.sleep(seconds), but it's not like LÖVE works. To create 10 boxes every 5 seconds you'd have to do:
If you used love.timer.sleep, you'd literally freeze the entire program and it wouldn't do anything until sleep time ends.
Do you know LÖVE callbacks and how it works?
Code: Select all
function love.load()
timer = 0
interval = 5
times = 10
end
function love.update(dt)
timer = timer + dt
if timer >= interval and times > 0 then
createBox()
times = times - 1
timer = timer - interval
end
end
Do you know LÖVE callbacks and how it works?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Very simple question on "Wait".
This would be an interesting use case for coroutines. It's a bit of an advanced subject, but the idea goes like so:
It's a little clunky in setting up, but the core of it is that you have a second thread of execution going that doesn't have to fall into love's event loop. As long as you resume in in love.update and yield from it without performing too much work, then things should go smooth (at least in principle).
Code: Select all
function love.load()
graphics = {}
game_thread = coroutine.wrap( game_runner )
end
function love.draw()
-- space filler, draw your stuff here.
for _, g in pairs(graphics) do draw(g) end
end
function love.update(dt)
game_thread(dt)
end
function wait( time )
repeat
time = time - coroutine.yield(true)
until time <= 0
end
function game_runner()
graphics.boy = sprite(10, 100)
graphics.girl = sprite(200, 100)
for x = 10, 190 do
graphics.boy.x = x
wait( 0.0333 )
end
wait(5)
graphics.heart = sprite( 200, 90 )
end
Re: Very simple question on "Wait".
Wait a sec... im I missing something? Drawing one more box every second is not a hard concept or program....
Here's some psuedo code:
Create table for images
load image
The love.update is here
Wait one second then set the total number of entries of the image table plus one to the image.
love.draw is here
Loop through the images and print each one.
I would have gave the actual code, but Im on my ipod.
Here's some psuedo code:
Create table for images
load image
The love.update is here
Wait one second then set the total number of entries of the image table plus one to the image.
love.draw is here
Loop through the images and print each one.
I would have gave the actual code, but Im on my ipod.
Re: Very simple question on "Wait".
Here's one way to do it.
Code: Select all
wait_time = 0
function wait(seconds)
wait_time = wait_time + seconds
end
function love.update(dt)
if wait_time > 0 then
wait_time = wait_time - dt
if wait_time > 0 then return end
dt = -wait_time
wait_time = 0
end
-- Update stuff
end
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 11 guests