Render: setMousePosition

setMousePosition(x,y)
  • Sets the position of the mouse cursor in the game window.

x:

  • pixel position of the mouse cursor in the x direction (game window width).
  • Type:  integer
  • Range:  0 to game window width
y:
  • pixel position of the mouse cursor in the y direction (game window height).
  • Type:  integer
  • Range:  0 to game window height
    Note:
    • (0, 0) is upper left corner of the game window.
    Sample Code

    ################  set the mouse cursor position

    # import bge module
    import bge

    # get the render module
    rend = bge.render

    # show mouse cursor
    rend.showMouse(True)

    # game window width
    width = rend.getWindowWidth()

    # game window height
    height = rend.getWindowHeight()

    # center of game window
    # make sure number is an integer
    x = int(width/2)
    y = int(height/2)

    # set the position of the mouse cursor to center of game screen
    rend.setMousePosition( x, y)