Hey all,
In programming up some mouse boundary code, I thought I'd do a search to see how others were working around this problem.
Here's a function I wrote. The workings of it are as follows;
* Remembers the mouse location upon pressing right click
* Hides, then centres the mouse location to the Window.
* The user then moves the mouse around whilst holding down the right button. Remember the cursor is hidden.
* If the mouse strays +/- 200 units from the centre, the if statements kick in which slowly return it to a 400x400 boundary around the centre of the Window.
* One interesting side effect, is that the mouse cursor never leaves the active game window. I believe this is the desired functionality?
*Upon releasing the mouse right button, the cursor is returned to its original location, and then shown. This part of my code is controlled in another function, not the one below.
Function Right_Click()
If mouseclick() = 2
Hide Mouse
If mouse.cursor = 0
Position Mouse ScreenSize.CentX, ScreenSize.CentY
endif
If Mouse.Cursor = 1
If Mouse.CaptureX < ScreenSize.CentX - 200
Position Mouse Mouse.CaptureX+1, Mouse.CaptureY
Endif
If Mouse.CaptureX > ScreenSize.CentX + 200
Position Mouse Mouse.CaptureX-1, Mouse.CaptureY
EndIF
If Mouse.CaptureY < ScreenSize.CentY - 200
Position Mouse Mouse.CaptureX, Mouse.CaptureY+1
Endif
If Mouse.CaptureY > ScreenSize.CentY + 200
Position Mouse Mouse.CaptureX, Mouse.CaptureY-1
EndIF
Cam.Xpos = Cam.Xpos + ((Mouse.CaptureX - ScreenSize.CentX) / 40)
Cam.Zpos = Cam.Zpos - ((Mouse.CaptureY - ScreenSize.CentY) / 40)
Endif
Mouse.Cursor = 1
Endif
Endfunction
Help build an online DarkBASIC Professional help archive.
http://dbprohelp.wikia.com/wiki/DarkBASIC_Professional_Help_Wiki