Page 1 of 1

What am I doing wrong? (Mouse + Screen)

Posted: Fri Feb 28, 2025 6:42 am
by Cyllceaux
Why is the moving of the mouse so slow?

I use this code:

Code: Select all

EnableExplicit

InitSprite()
InitMouse()
InitKeyboard()



Define window=OpenWindow(#PB_Any,0,0,800,600,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

OpenWindowedScreen(WindowID(window),0,0,800,600)

Define sprite=CreateSprite(#PB_Any,64,64)


Repeat
	
	FlipBuffers()
	ClearScreen(RGB(200,200,200))
	
	Delay(1)
	
	ExamineMouse()
	ExamineKeyboard()
	
	
	DisplaySprite(sprite,MouseX(),MouseY())
	
	If KeyboardPushed(#PB_Key_Escape)
		CloseWindow(window)
		Break
	EndIf
	
	If IsWindow(window)
		If WaitWindowEvent(10)=#PB_Event_CloseWindow
			Break
		EndIf
	EndIf
	
ForEver

CloseScreen()
But if I use Window mouse, it's fast

Code: Select all

EnableExplicit

InitSprite()
InitKeyboard()



Define window=OpenWindow(#PB_Any,0,0,800,600,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

OpenWindowedScreen(WindowID(window),0,0,800,600)

Define sprite=CreateSprite(#PB_Any,64,64)


Repeat
	
	FlipBuffers()
	ClearScreen(RGB(200,200,200))
	
	Delay(1)
	ExamineKeyboard()
	
	
	DisplaySprite(sprite,WindowMouseX(window),WindowMouseY(window))
	
	If KeyboardPushed(#PB_Key_Escape)
		CloseWindow(window)
		Break
	EndIf
	
	If IsWindow(window)
		If WaitWindowEvent(10)=#PB_Event_CloseWindow
			Break
		EndIf
	EndIf
	
ForEver

CloseScreen()

Re: What am I doing wrong? (Mouse + Screen)

Posted: Fri Feb 28, 2025 7:50 am
by pjay
It's possible the mouse commands in WindowedScreen mode are dependent on proper event processing.

If you're only handling a single event per frame, but your OS is producing 100s of events, then you get backlog (i.e. lag).

Typically you'd process all events in a loop, per frame:

Code: Select all

	Repeat
	  event = WindowEvent()
	  Select event
	    Case #PB_Event_CloseWindow : Break
	  EndSelect
	Until event = 0

Re: What am I doing wrong? (Mouse + Screen)

Posted: Fri Feb 28, 2025 9:18 am
by Cyllceaux
Oh... I followed the Help: https://www.purebasic.com/documentation ... creen.html
There is WaitWindowEvent(10)

Re: What am I doing wrong? (Mouse + Screen)

Posted: Fri Feb 28, 2025 1:30 pm
by pjay
Cyllceaux wrote: Fri Feb 28, 2025 9:18 am Oh... I followed the Help: https://www.purebasic.com/documentation ... creen.html
There is WaitWindowEvent(10)
Yes, you're right, but so is:

Code: Select all

 ; It's very important to process all the events remaining in the queue at each frame
:)

Re: What am I doing wrong? (Mouse + Screen)

Posted: Sat Mar 01, 2025 7:53 am
by Cyllceaux
:oops: I saw my Mistake...

thanks to you!