Nailing Down SMBX FPS and Event/Layer Timing
Posted: Thu Apr 28, 2016 11:39 pm
Supposedly SMBX runs at 65 frames per second, at least according to the FPS counter. However, I'm trying to sync the timing of events in a particular section of my level to music, and noticed that 65 ticks per second isn't really that accurate.
Using this code:
I get about 64.1 ticks per second, not 65. I'd like to know what other people get on other systems.
...But that doesn't matter too much to most people. What really matters (at least when you're not using LunaLua) is the timing on moving layers.
I measured the number of ticks between a pair of events triggering each other on a given delay, causing a block to move up and down. As expected, at speed 1 the block moved the same distance as the number of ticks (speed being measured in pixels per tick, where a block length = 32 pixels). The number of ticks, however, turned out strange:
No wonder it's so hard to prevent cycling layers from getting farther and farther off if you don't use the same speed and delay both ways. A 2 second delay isn't even the same as two 1-second delays!
Natsu said in this thread that, effectively, the distance moved is speed*time*65. This is pretty close, but you can't have a fraction of a tick. The number of ticks for a given number of seconds appears to be:
(seconds*65)+1, rounded to the nearest ODD number if it ends in .5
Normally .5 is rounded to the nearest even number, but presumably it's rounded before the 1 is added, resulting in it rounding towards odd numbers instead.
In that case the distance moved is:
speed*((seconds*65)+1, rounded to the nearest ODD number if it ends in .5)
The extra 1 is what tends to throw off the timing of layers. For example, a speed of -1 for 2 seconds and a speed of 2 for 1 second moves the layer -131 and then +132, causing it to go further off by 1 each cycle.
However, moving it by -1 for 1 second and +2 for 0.5 seconds does work because the number of ticks for 1 second is twice the number for 0.5 seconds. Another solution is to split up the first delay, so you have the layer moving -1 for 1 second, then -1 for 1 second again, then +2 for 1 second.
It's all in how the ticks add up. I hope this is helpful!
Using this code:
Spoiler: show
...But that doesn't matter too much to most people. What really matters (at least when you're not using LunaLua) is the timing on moving layers.
I measured the number of ticks between a pair of events triggering each other on a given delay, causing a block to move up and down. As expected, at speed 1 the block moved the same distance as the number of ticks (speed being measured in pixels per tick, where a block length = 32 pixels). The number of ticks, however, turned out strange:
Spoiler: show
Natsu said in this thread that, effectively, the distance moved is speed*time*65. This is pretty close, but you can't have a fraction of a tick. The number of ticks for a given number of seconds appears to be:
(seconds*65)+1, rounded to the nearest ODD number if it ends in .5
Normally .5 is rounded to the nearest even number, but presumably it's rounded before the 1 is added, resulting in it rounding towards odd numbers instead.
In that case the distance moved is:
speed*((seconds*65)+1, rounded to the nearest ODD number if it ends in .5)
The extra 1 is what tends to throw off the timing of layers. For example, a speed of -1 for 2 seconds and a speed of 2 for 1 second moves the layer -131 and then +132, causing it to go further off by 1 each cycle.
However, moving it by -1 for 1 second and +2 for 0.5 seconds does work because the number of ticks for 1 second is twice the number for 0.5 seconds. Another solution is to split up the first delay, so you have the layer moving -1 for 1 second, then -1 for 1 second again, then +2 for 1 second.
It's all in how the ticks add up. I hope this is helpful!