I want to use the mouse to give the player the ability to look in any direction (kind of like a FPS). The problem I am having is that the mouse exits the screen and I do not want it to.
I made a hack where the pointer is repositioned to the center once it approaches the edges of the screen but this results in jittery play.
Is there a better solution to keep the mouse within the game window.
What method do you use to recenter the mouse? We use essentially that technique in our first-person views, and we don’t see any jitter.
Instead of re-centering the mouse when it nears the edge of the screen, try re-centering it every frame. You can still move the mouse outside the edge if a frame takes an inordinate amount of time to draw, but that’s a more rare occurrence.
My original thought was to recenter the mouse after every frame in my game task but this resulted in the mouse not being able to move. I’m using this to recenter my mouse:
I, too, am trying to lock the cursor to the window. I tried this code and looked at AirBlade but it doesn’t do anything.
def checkMousePos(self):
#if (self.ship.getZ() > 6):
# self.ship.setZ(6)
if (base.mouseWatcherNode.hasMouse()):
x=base.mouseWatcherNode.getMouseX()
y=base.mouseWatcherNode.getMouseY()
self.ship.setX(x)
self.ship.setY(y)
else:
print "No mouse!"
# Put the mouse in the center
bTR = base.win.movePointer(0, base.win.getXSize()/2, base.win.getXSize()/2)
print str(bTR)
#print str(x)+" is mouse X"
#print str(y)+" is mouse Y"