What am I doing wrong? (Mouse + Screen)

Just starting out? Need help? Post your questions and find answers here.
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

What am I doing wrong? (Mouse + Screen)

Post 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()
pjay
Enthusiast
Enthusiast
Posts: 277
Joined: Thu Mar 30, 2006 11:14 am

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

Post 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
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

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

Post by Cyllceaux »

Oh... I followed the Help: https://www.purebasic.com/documentation ... creen.html
There is WaitWindowEvent(10)
pjay
Enthusiast
Enthusiast
Posts: 277
Joined: Thu Mar 30, 2006 11:14 am

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

Post 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
:)
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

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

Post by Cyllceaux »

:oops: I saw my Mistake...

thanks to you!
Post Reply