1. Verge Integers always round down to zero. Even if the result would be greater than 0.5, it would still round down to zero. All decimal data is discarded.
2. Perhaps you should use fixed point.
3. HookTimer is reliable, because it always calls a function a set number of seconds. You can essentially make your own HookTimer procedures in code using just the 'timer' variable. You keep track of how many centisecs has passed, and then you call the function enough times to catch up.
while (timer - lasttime > 0)
Call Function
lasttime++
It's almost that simple. The only problem is when you time a function that just can't be completed in less than a centisec, in which case lasttime will never catch up to timer, and a HookTimer version would also fall behind and start to do bad stuff. That's why you don't put graphics or anything potentially time consuming in HookTimer.
But, as long as the function can be completed in a 1/100th second time window, then HookTimer will always reliably call it, because it works by simple looping, essentially. There's no way it shouldn't be able to catch up unless you're doing something wacky like per-pixel.
4. Now, my own explanation of moving an entity 4 pixels. Keep in mind I haven't read RageCage's math (reading someone else's math code is kinda hard for me to follow :) ) so I'll just try to summarize what I would do.
1 You want to move an entity 4 pixels in a second.
2 That means in 100 centisecs, the entity moves, 4 pixels. Of course.
3 So, 100 must equal 4 pixels, or technically 4 pixels per 100 centisecs, or, simplified, 1 pixel per 25 centisecs, or whatever.
Try this.
Pseudo-code
define real X position of the entity real_x
define time to move per second. pixel_per_sec = 4
int global variable seconds_counted
void MoveMyEntity()
while (timer - lasttime > 0)
seconds_counted++
if (seconds_counted == 100 / pixel_per_sec)
//IE, the correct number of centisecs have passed, in this case 100/pixel_per_sec = 25
seconds_counted = 0
real_x++
lasttime++
HookTimer(Move_My_Entity)
And I think that would essentially do it. EDIT: RageCage's first example also looks good and probably simpler :)
5. Also, try taking a look at this.
http://www.verge-rpg.com/files/detail.php?id=577
It's the framethrotlling code I made a while back. It allows you to set the functions to be called, and then lets you set a Max FPS and a frameskip that WILL be maintained.
For example, in the demo the starting settings rotate a picture of Interference's font at exactly 6 degrees a second at 60 FPS. So, every second the font makes a complete revolution, since 6 degrees * 60 frames = 360 degrees per second. That's not the same as pixel velocity, but you could make it work, and it's an interesting alternative to HookTimer since it also lets you potentially do neat things like cut down the FPS for ZSNES-style slow motion :)