umm... timer in DirectX?
Posted: Wed Jun 28, 2006 11:47 am
how do i do a 40 second countdown in a DirectX screen (within a continous loop)?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
t=ElapsedMilliseconds()
Repeat
ExamineKeyboard()
ClearScreen(#ScrnColor)
DisplaySprite(#sprite1, s1x, s1y)
DisplaySprite(#sprite2, s2x, s2y)
DisplaySprite(#sprite3, s3x, s3y)
FlipBuffers()
Delay(1)
If ElapsedMilliseconds()-t >=40000
; Timer expired
EndIf
Until KeyboardPushed(#PB_Key_Escape)
Code: Select all
tm.l = GetTickCount_() + 40000
While GetTickCount_() < tm
; whatever
WendCode: Select all
tm.l = GetTickCount_() + 1000
While GetTickCount_() < tm
pTime-1
Wend
Code: Select all
starttm.l= GetTickCount_()
maxtm.l = starttm + 40000
runningtm.l = starttm + 1000
repeat
repeat:until GetTickCount_()> runningtm ;counts off 1 second
pTime-1 ;update counter
;display of time goes here
runningtm+1000 ;this adds a second onto previous value so we don't get time creep
currenttm=GetTickCount_()
until currenttm>=maxtm
Code: Select all
Global countDown.l
Procedure displayCountDown()
StartDrawing(ImageOutput(0))
Box(0,0,100,100,$000000)
DrawText(40,40,Str(countdown),$FFFFFF,$000000)
StopDrawing()
SetGadgetState(0,ImageID(0))
EndProcedure
Procedure timerCallBack(hWnd.l,uMsg.l,idEvent.l,dwTime.l)
countDown - 1
If countDown < 0
KillTimer_(WindowID(0),idEvent)
Else
displayCountDown()
EndIf
EndProcedure
countDown = 4
CreateImage(0, 100,100)
OpenWindow(0, 0,0, 100,100, "Junk", #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ImageGadget(0, 0,0, 100,100, ImageID(0))
SetTimer_(WindowID(0),1,1000,@timerCallBack())
displayCountDown()
Repeat
ev.l = WindowEvent()
If ev = #PB_Event_CloseWindow
End
EndIf
Delay(1)
Until countDown < 0
HideGadget(0,#True)
Repeat
ev.l = WaitWindowEvent()
Until ev = #PB_Event_CloseWindow
End