-
More precise timer?
Hello,
I am using the demo version to try to create a sort of rhythm game (kind of like Lumines) and I'm struggling with getting an accurate timer. Here is my problem: I need an event to occur on every 'beat' of the song - however, the timer is only accurate to 1/100th of a second. This creates a problem that when I call this event every, for example, 0.69 seconds, after about thirty seconds of game time, the beat will be noticably off with the timer. This is because I need the event to occur every 0.69535 seconds, but I have to round alot of important information because the timer isn't precise enough.
I tried setting a counter to the amount of time elapsed since the frame has begun (which for some reason is in 1/1000th of a sec) and tried using (Timer)mod(695) [if my event needs to occur every .695 seconds], and check when the result is zero. I thought this might be a clever way to get a more precise timer, however the events seem to occur so fast that the condition == 0 is rarely ever triggered at all.
Is there anything I can do to force it to give me a more precise timer , using any tricks perhaps? Or maybe a bit of mathematical genius to create some sort of "offset" or "padding" to add to the counter every so often in order to keep it syncronized with the songs beat?
Anyone ever try to create an application like this before?
-
Re: More precise timer?
Events in MMF2 are only checked on every frame no matter how accurate the timer is - and with a default FPS of 50, that makes the timer being divisible by 695 on any frame pretty unlikely - that caused the behaviour that you saw.
What format is the song in? I know that ModFusion has a "Get beat" action or something similar, but I've never tried it so I'm unsure as to its usefulness.
-
Re: More precise timer?
FireMonkey once made an extension for MMF1.5 for a similar problem (though his was the reverse of this?), I believe. However, I don't think it was converted and he may no longer have the source or even be around...
http://www.clickteam.com/CTforum/showflat.php3?Cat=&Board=upload&Number=144747&page =&view=&sb=&o=&vc=1
-
Re: More precise timer?
It is an example and scriptlet/widget, not an object.
-
Re: More precise timer?
-
Re: More precise timer?
I sort of figured it out using the modulus technique. I just set a counter to the (timer)mod(461.538) [event occurs every .461538 seconds], and whenever the user presses a key in sync with the beat, I can use the value of that counter to determine exactly how close the key press was to the actual beat. Using this method gives me 6 decimal point precision - and the beat will be perfectly syncronized with the song all the way through.
However, using this technique, I won't be able to count the beats - since I can't rely on the game catching the counter at 0 - this doesn't really affect the game though as it's not really necessary information for my application, and I'm thinking I would even be able to twist some things around to get a beat counter anyways.
My only concern is how well this will transfer over to other computers, and if any noticable differences could take place from machine to machine... if anyone wants to help maybe I could upload my test project so far and see how it runs on your guys machines?
-
Re: More precise timer?
You may want to enable "machine independent speed" in application properties.