Trouble with ElapsedMilliseconds()
Posted: Wed Oct 14, 2015 11:06 am
Hello,
I simply don't understand ElapsedMilliseconds()
I am trying to develope a small fun prog wherein a number of moving sprites could be hovered and during this event should be allowed to be clicked to start the follow-up gimmik.
Well at first I had tried to implement ExamineMouse() to be only active during this hoverevent but I couldn't exclude the later called ReleaseMouse() being already processed and thus corrupting ExamineMouse().
So I moved to a different way to handle it hoping I could catch the duration time while the mouse is continuously hovering over a targeted sprite. And if a certain amount of time is tresspassed it should trigger that follow-up gimmik.
But nothing I've tried would work reliable ... only just occasionally.
Can you give me a hand please how I could determine the duration time of a hover event?
greets ~ Vera
I simply don't understand ElapsedMilliseconds()

I am trying to develope a small fun prog wherein a number of moving sprites could be hovered and during this event should be allowed to be clicked to start the follow-up gimmik.
Well at first I had tried to implement ExamineMouse() to be only active during this hoverevent but I couldn't exclude the later called ReleaseMouse() being already processed and thus corrupting ExamineMouse().
So I moved to a different way to handle it hoping I could catch the duration time while the mouse is continuously hovering over a targeted sprite. And if a certain amount of time is tresspassed it should trigger that follow-up gimmik.
But nothing I've tried would work reliable ... only just occasionally.
Can you give me a hand please how I could determine the duration time of a hover event?
greets ~ Vera
Code: Select all
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 300, 200, "hover duration ?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 20, 0, 45, 20, "Quit")
OpenWindowedScreen(WindowID(0), 0, 20, 300, 180, 0, 0, 0)
CreateSprite(0, 20, 20)
If StartDrawing(SpriteOutput(0))
Box(5, 5, 20, 20, RGB(255, 0, 155))
StopDrawing()
EndIf
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadget() = 0
End
EndIf
Case #PB_Event_CloseWindow
Exit = #True
EndSelect
Until Event = 0
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
DisplaySprite(0, 50, 50)
startTime = ElapsedMilliseconds() ;: Debug startTime
MouseX = WindowMouseX(0)
MouseY = WindowMouseY(0)
If MouseX > 50 And MouseX < 70 And MouseY > 50 + 20 And MouseY < 70 + 20
; Debug "hover box"
Repeat
Delay(1)
; Debug ElapsedMilliseconds() - startTime
If ElapsedMilliseconds() - startTime > 10
Debug "duration reached"
Debug ElapsedMilliseconds() - startTime
Else
stop = 1
EndIf
Until stop
EndIf
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or Exit