Movement speed
Blitz3D Forums/Blitz3D Beginners Area/Movement speed
| ||
I have a question about movement speed. I have a 2d program with a little picture movement. The image moves every flip 2 pixels... On a computer thats running 85Hz for the monitor, the movement goes faster than on a computer thats used 60Hz. Is there a way to make them move on the same speed? Greetz And thnx Tom |
| ||
Search for 'delta timing' and 'render tweening'. Both of these are established methods of achieving smooth movement across various hardware. You should finds lots of info if you search these forums (and others) using 'delta' and 'tween'. there were some excellent tutorials on BlitzCoder which has now merged with CodersWorkshop, so hopefully you can find them there. http://www.codersworkshop.com/ Rhy :) |
| ||
The problem is, while your logic will be able to make it move framerate idependently at a constant speed, it will become jerky if you move it EG. 1.58 Pixels per frame. so if you use Blitz3D, you should think about to jump on the "pseudo-2d by 3d" bandwagon. You will use sprites or quads that are facing to the camera instead of simple 2D images. There are several Sprite Systems that will act as a 2D emulation. Now when you move such a 2D-3D-Sprite by say 0.25 pixels, it won't be limited to full pixel steps as in 2D. Additionally you will get antialiased contours. No matter if you use 3D-2D or real 2D, you need to use Floats for the positions as well as to time the motion with realtime information EG: mon_ms#=1000.0 / 85.0 t=millisecs() - mon_ms# xstep#=1.0 while not keydown(1) ; game loop t2=t t=millisecs() delta#=float(t-t2)/mon_ms# ... pic_x#=pic_x# + (xstep# * delta#) ... flip wend |
| ||
As another option, you can always go the timer route, e.g.fps_timer = CreateTimer(60) ; Main loop. While Not KeyHit(1) . . . WaitTimer(fps_timer) VWait : Flip False Wend |
| ||
If your gamelogic is simple or you are aiming for higher end machines you could run your gamelogic at 1000 ticks per second (or something more sensible maybe) and have the game draw screen updates at whenever it wants. |
| ||
Thnx for the reply's... I'm making a simple 2d game. I go try it, and let you now if somthing goes wrong Tom |