The player click ouside the game windows.

BlitzMax Forums/BlitzMax Beginners Area/The player click ouside the game windows.

hub(Posted 2010) [#1]
Hi !
Imagine : the player have a 1024x900 resolution monitor. So it lauch my vertical shoot game inside a 1024x768 window. (Windows Os). This is his choice (in fact my game could run at any resolution...).

The player control the ship with the mouse and use the left click to shoot. But if i click ouside the game window the game stop. The windows is desactived and minimazed by XP ! (in fact the game is automatically set to pause)

So how to avoid this !

Thanks !

Last edited 2010


Jesse(Posted 2010) [#2]
I have seen some games do that. My only suggestion is to lock the mouse down to the game area with MoveMouse while the game is playing. I have noticed that some graphics modes give the mouse position even outside of the window and others don't so you might have some problems there.


hub(Posted 2010) [#3]
In fact the problem is the mouse click outside the window as the ship movement as already limited to an area. it seems not exist a method for this.


TaskMaster(Posted 2010) [#4]
Hide the mouse and draw your own mouse pointer.

Keep the real mouse locked down to the center of the window, when the user moves the mouse, move the one you are drawing, and put the real mouse into the middle of the window again.

Then, when a menu or pause screen is up, show them the real mouse so they can use it to leave the window if they need to.


hub(Posted 2010) [#5]
nice idea thanks !


hub(Posted 2010) [#6]
Could you try this ?



TaskMaster(Posted 2010) [#7]
Seems to work. That is what I was thinking as a solution.


hub(Posted 2010) [#8]
but this code seems to me strange. Why the true mouse pointer move on the screen ! I use movemouse at fixed position ! Is the technic available inside a true game (with time limiting, ...). I've some difficulties to adapt this inside my project.


Jesse(Posted 2010) [#9]
blitzmax uses functions to access and modify the position of the system mouse and that is the reason mousexspeed and mouseyspeed work. the mouse position gets updated with out regard to your game. Use HideMouse() to solve(should solve) your problem.

Last edited 2010


hub(Posted 2010) [#10]
uncomment the drawtext line and the code not work ! Please help me !

Last edited 2010


Jesse(Posted 2010) [#11]
that is odd. I think it's the way polled input hook works. it might be updated after x amount of time which your code might be going to fast but that is just a guess.
anyway, I believe this fixes it:
Strict
Graphics 800,600

Local mx#,my#

	mx# = 0
	my# = 0

While Not KeyDown (KEY_ESCAPE)

	Cls
	mx# = mx# + MouseXSpeed() 
	my# = my# + MouseYSpeed() 
	
	If mx# < 0 Then mx#=0
	If mx# > GraphicsWidth() Then mx# = GraphicsWidth()
	If my# < 0 Then my# = 0
	If my# > GraphicsHeight() Then my# = GraphicsHeight()
	
	
	SetColor 0,255,0
	DrawRect mx#-10,my#-10,20,20
	SetColor 255,255,255
	Plot mx#, my#

	MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
	MouseXSpeed() '****************************************************
	MouseYSpeed() '****************************************************
	
	'DrawText "Mx=" + mx# +  "My=" + my# + ",mxs=" + MouseXSpeed() + "mys=" + MouseYSpeed(),0,0
	
	Flip()
	
Wend 



TaskMaster(Posted 2010) [#12]
Your MoveMouse() command is generating MouseXSpeed() and MouseYSpeed() Values. That is why it is making your drawn mouse return to center.

So, when you call the MouseXSpeed and MouseYSpeed values in the DrawText, you are taking those values out so they do not get read in on the beginning of the next loop.

Last edited 2010


TaskMaster(Posted 2010) [#13]
What you might want to do is get the mouse position yourself and update your mouse with that. Rather than use MouseSpeed commands. Then you want have this problem.

Last edited 2010


hub(Posted 2010) [#14]
Thanks for the explanation. i've just applied Jesse fix inside my project and it works now too. Hope it is a good choice. Perhaps somebody could post here a better code.


Jesse(Posted 2010) [#15]
I just looked at the source for the module for Poled input and it does exactly what TaskMaster pointed out. It really won't make "much" difference if you implement your own, you will have to do almost the same thing. once you center it, you will have to clear the movement variables in order to get an accurate movement value every time the mouse is moved.


TaskMaster(Posted 2010) [#16]
Here ya go:




Jesse(Posted 2010) [#17]
My small brain would have never thought of that approach. nice and thanks for taking the time to figure it out and posing it.


matt!(Posted 2011) [#18]
Many thanks for this very elegant solution!


matt!(Posted 2011) [#19]
The only issue I've found with this is that it becomes impossible to reposition the window by dragging the title bar.

Here's the solution, using EVENT_MOUSEENTER and EVENT_MOUSELEAVE:



Last edited 2011