I was looking for a way to create timers (i.e. do this in x seconds) in orx. I can't find a easy way to do it via the API, but I assume this is done somehow internally (since objects have can have a lifetime)? Is there a main clock that keeps track of it or do each object have their own clock?
Right now I cheat a bit and do this myself with FXs, so if I want an object to be slowed down a while, for example, I add an empty FX named Slow. I was just curious if there was any better ways of doing it
However, there's a main clock (the core one), that can be found like this:
When you have this clock, you can get its info (orxClock_GetInfo()). The info structure is public and contains the DT, the DT modifier and the elapsed time since its creation.
Now the objects are updated using the main clock by default but we can associate a clock to an object now.
Either in config (Clock = MyClock + look at CreationTemplate.ini to see how to declare a clock) or at runtime with orxObject_SetClock(). If you look at MushroomStew's code (aka ProjectX), I use this to slow down objects.
Slowing down objects with clocks is better than with FX as it'll modify all the aspect of the object (speed, sound pitch, etc).
Hope this helps!
The reason I used FXs is that I wanted an easy way to add several "timed properties" on an object and to keep track of them. For example, in my tower defence game I want to be able to make the enemies move slower but also something that increases damage taken.
If you sync orx, you'll find timer handling functions.
You can add timers on any clock you want, or if you want to add them on the main clock, just use the *Global* version of the functions.
You have orxClock_AddTimer()/orxClock_RemoveTimer. You have to give a strictly positive delay (used between 2 calls of the timer) and you can specify a repetition number. If you give -1, the timer will be called infinitely.
When removing a timer, you have to give the associated callback function and an optional delay. If the delay is -1, any timer matching the callback function will be removed.
If the delay is strictly positive, only the timer matching both the delay and the callback will be removed.
If you have any comments/suggestions regarding the timers, please let me know!
I'm downloading the source right now. I guess it's been a while since I updated so there's a lot to download.
I'll get back once I've tried it out.
The following is logged in the debug log (I hope it's readable):
The following is in my ini-files:
It's adding the "Bump" fx that causes the assertion fail. I've tried both with and with-out quotes for the String value in [ScoreText].
Any ideas what might cause this?
Timers seem to work fine though .
As for the crash, it's a very interesting one! ^^ Which version of orx are you using? The embedded one or the other?
I'd suggest to rebuild orx to make sure everything is based on the same .h include files as the structure IDs have been changed. Make sure you also use the latest .h files for your own project along the rebuilt .lib/.dll. Lastly, try to rebuild your own project.
If you still have the errors afterward, would you mind making a zip with your project (source, include + solution/workspace) so that I can try locally to see what's going wrong?
So everything's working now? I had similar issues with TortoiseSVN at some point, but it didn't happen for a couple of weeks now. I have no idea what went wrong either.
As for the timers, they work great. They really simplify things for me, so thanks for that. I haven't checked how accurate they are, but I assume they're about as accurate as the clock they run on.
Their precision is the exact same one as the clock. So if you register them on a 60Hz clock, their precision is 1/60s (not including the OS-dependent time precision which is too small to be taken in account here).
Also note that the timers are influenced by the time modifier of the associated clock, ie. if you slow down the clock, timers will also slow down.
Lastly, you can safely remove a timer from within its callback. For example, if you register a timer with a function MyTimer() and a repetition of -1 (infinite), you can safely remove this timer with a call to orxClock_RemoveTimer() from inside MyTimer(). The timer is actually flagged as obsolete and memory will be freed during the next clock update.