Delay millisecs
Parameters
| millisecs - how long to pause for, in milliseconds; 1000 is one second |
Description
|
Pauses the program for the given number of milliseconds. Nothing of yours runs during a Delay - no drawing, no input, no updates. The window still responds to Windows while it waits, so the program will not appear frozen and can still be closed, but your game loop is stopped dead. That makes Delay right for a handful of jobs and wrong for most. It is fine for a deliberate pause on a splash screen, for slowing down a console-style demo so its output is readable, or for Delay 1 inside a spin-wait to stop a background loop burning a whole CPU core. It is the wrong tool for animation timing, cooldowns or pacing, because everything else in your game stops too. For those, compare readings from MilliSecs and keep looping, or use CreateTimer and WaitTimer, which pace a loop without blocking the rest of the frame. Delay 0 does not pause but does give Windows a chance to process messages, which is occasionally useful in a tight loop. See also: MilliSecs, CreateTimer, WaitTimer, VWait, Flip. |
Example
; Delay Example ; ------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Delay halts the ENTIRE program for the given number of milliseconds. ; Nothing runs and no input is read while it waits, so long delays make ; a game feel frozen - but a short delay is a simple way to pace a loop. pause=10 While Not KeyDown(1) Cls ; 1/2/3 choose how long each frame stops inside Delay If KeyHit(2) Then pause=10 If KeyHit(3) Then pause=100 If KeyHit(4) Then pause=500 ; The square moves one step per frame, so a longer Delay ; means jerkier motion and slower key response x=(x+4) Mod 640 Rect x,220,40,40,True Text 0,0,"1: Delay 10 2: Delay 100 3: Delay 500 Esc: exit" Text 0,20,"Delay "+pause+" every frame - try the keys and feel the difference" Flip ; The documented command: stop everything for 'pause' milliseconds Delay pause Wend End
Index