What, how?kraftman wrote:You could give each thing that you want to fade in its own timer.
Question from a LOVE newbie
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Question from a LOVE newbie
Re: Question from a LOVE newbie
Do what i typed and add Some more D's if you know what i mean.
Re: Question from a LOVE newbie
local myobject = {}Anooxy wrote:What, how?kraftman wrote:You could give each thing that you want to fade in its own timer.
myobject.alpha = 0
local myobject2 = {}
myobject2.alpha = 0
Re: Question from a LOVE newbie
diffrent timers example =
Code: Select all
timer1 = 0
timer2 = 0
timer3 = 0
function love.update(dt)
timer1 = timer1+dt
timer2 = timer2+dt
timer3 = timer3_dt
if timer1 > 1 then
timer1 = 0
--do stuff
end
if timer2 > 3 then
timer2 = 0
--do stuff
end
if timer3 > 10 then
timer3 = 0
--do stuff
end
end
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Question from a LOVE newbie
Or, you know, use a single timer, but a better test. So something like:
Code: Select all
if timer > 10 and timer < 15 then
Re: Question from a LOVE newbie
GijsB wrote:diffrent timers example =
Code: Select all
timer1 = 0 timer2 = 0 timer3 = 0 function love.update(dt) timer1 = timer1+dt timer2 = timer2+dt timer3 = timer3_dt if timer1 > 1 then timer1 = 0 --do stuff end if timer2 > 3 then timer2 = 0 --do stuff end if timer3 > 10 then timer3 = 0 --do stuff end end
Using global variables as timers for objects is a pretty messy way of doing it. A better way would be to give each object its own timer, and use a loop to update the timers. Or to have a table that is looped through on update, and have objects that need adjust each update hook into that table.
Re: Question from a LOVE newbie
If you were to use a lot of timers, you could create a class which takes care of a whole bunch of timers, store them in a table, sorts them based on when they are going to be activated, and then it just has to check the one closest to be activated all the time. I was thinking about doing something like this in my game.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: Question from a LOVE newbie
There are also libraries to aid in this http://vrld.github.com/hump/#timer
Re: Question from a LOVE newbie
oke, i made this (i dont even know if it works )
Code: Select all
timers = {}
function love.update(dt)
for i,v in pairs(timers) do
v.time = v.time+dt
v.on = false
if v.time > v.maxtime then
v.time = 0
v.on = true
end
end
end
function addtimer(t)
newtimer = {time = 0, maxtime = t,on = false}
table.insert(timers,newtimer)
return timers.newtimer
end
timer1 = addtimer(10)
if timer1.on then--this doesnt work, but how CAN i make it work 3:?
--blabla
end
Re: Question from a LOVE newbie
This probably belongs in another topic. The code won't work for a number of reasons. It's worth reviewing how variable scoping works in Lua, as well as table indexing and the love.update() function.GijsB wrote:oke, i made this (i dont even know if it works )
Code: Select all
timers = {} function love.update(dt) for i,v in pairs(timers) do v.time = v.time+dt v.on = false if v.time > v.maxtime then v.time = 0 v.on = true end end end function addtimer(t) newtimer = {time = 0, maxtime = t,on = false} table.insert(timers,newtimer) return timers.newtimer end timer1 = addtimer(10) if timer1.on then--this doesnt work, but how CAN i make it work 3:? --blabla end
Who is online
Users browsing this forum: Google [Bot] and 3 guests