"Romans_I_XVI" wrote:
Do you have a suggestion/example of how to go about switching the sprite movement to time based instead of frame based? I would appreciate it very much. I am kinda excited now, because if I fix this I think it will actually run very smooth.
Actually you don't need any of these "easing"/tweening functions, using them in your game will be backwards - they will work well when you know you want to move an object from point A to point B with certain dynamic behavior. In your game though (warning - haven't tried it but i think i glanced youtube video of yours) is much more likely you are simulating physics, so if an object was at position (x,y) and moves with constant speed vector (Vx, Vy), then after certain amount of time dt, the new positions would be
x_new = x + Vx * dt
y_new = y + Vy * dt
Trivial, right? Now when we add acceleration (Ax, Ay) - say caused by force of jet engine, we'll need to update the velocity in the same way (it doesn't matter if that is done before or after position update but should be done consistently):
Vx_new = Vx + Ax * dt
Vy_new = Vy + Ay * dt
And you do that before every redraw/every frame (could less or more often but let's keep it simple). Ok but how much is dt (time delta)? Quite simply, the difference between the time of previous frame and the current one:
newTime = tmr.totalMilliseconds()
dt = newTime - oldTime
oldTime = newTime
And all that is left is to decide on what the object speeds/accelerations will be - in pixels/ms. But i assume you already have most of this done, except in pixels/frame. So convert them by dividing by how many milliseconds/frame based on your "golden standard" of player you tuned it for. E.g. assuming you got 30fps (if using double-buffered roScreen, average fps will be either 30fps or 60fps because of effect of Vsync), that's 33ms/frame. Say object's speed was 33 pixels/frame, divided by 33 ms/frame = 1 pixels/ms. And now when using deltaT on redraw, if still having 30fps, the time elapsed since previous frame will be 1000 ms / 30 ~= 33 ms, x 1 px/ms = 33 pixels, like before! But say you are on slow/old player and it only can crank about 15 fps, well then time since previous frame will be 67 ms, x 1 = 67 px - so the object will move 67 px per frame but since there are only 15 frames/sec, it will travel the same distance per second on both players (1000px/sec) and game dynamics will be the same. Except on faster player it will run "smoother", on really slow may seem chunkier/jumpy - but as responsive. If you think about it some more, maybe you'd agree the frame-based kinematics was actually a complication, compared to a time-based one.
So practically speaking, there is precious little to do to upgrade it to time-based movement - just replace pixel/frame speeds with pixel/ms and measure time from previous frame (single timer is enough) and you are GTG