frequency = required tick events per second |
This command will create a timer that will generate a Timer Tick event at the requested frequency.
Use this command in conjunction with the WaitEvent or WaitTimer to control the speed of program execution. You will typically use this in your main screen redraw loop to control the playback speed to match the desired number of frames per second. The frequency should be set to the number of frames you require per second, allowing you to draw each frame on receipt of each tick event. This will prevent your games from playing back too fast on computers faster than yours. Use of this system is VERY GOOD practice, as your game will be played on a variety of computers. If you use WaitTimer, program execution halts until a tick event is received. If you use WaitEvent, the CPU is free to perform alternate tasks until a tick event is received. Therefore it is recommended that you use the WaitEvent method in preference to WaitTimer. You should never use the WaitTimer AND WaitEvent methods of controlling speed at the same time, as you will 'lose' ticks. See also: WaitTimer, WaitEvent, TimerTicks, ResetTimer, PauseTimer, ResumeTimer, FreeTimer. |
; create a window
WinHandle=CreateWindow("Timer Functions",100,100,200,150,0,25) ; and create a couple of buttons buttonReset=CreateButton("Reset Timer",10,10,180,20,WinHandle) buttonPause=CreateButton("Pause Timer",10,40,180,20,WinHandle) ; and create our timer (one hundred ticks per second) timer = CreateTimer(100) ; and now a loop to demonstrate it in action Repeat event=WaitEvent() ; exit when we receive a Window Close event If event=$803 Then End ; reset / pause / resume the timer if the user hits the buttons If event=$401 Then If EventSource()=buttonReset Then ResetTimer timer If EventSource()=buttonPause Then If GadgetText(buttonPause)="Pause Timer" Then PauseTimer timer SetGadgetText buttonPause,"Resume Timer" Else ResumeTimer timer SetGadgetText buttonPause,"Pause Timer" End If End If End If ; update the screen on timer tick If event=$4001 Then time# = TimerTicks(timer)/100.0 SetStatusText WinHandle,"Ticks : " + TimerTicks(timer) + ", Time : " + time + " seconds" End If Forever End ; bye! |