Mouse Cursor

Mouse Cursor Guide

Mouse Cursor in Game Programming

The mouse cursor is the pointer with which you point. The mouse cursor has two components. The mouse cursor image itself and the position of the mouse cursor on the screen.

Mouse Cursor Image

The default mouse cursor image is a part of Windows. You can turn on and off (show or hide) the mouse cursor by using theMouse function.

Mouse Cursor Position

Check Mouse Cursor Position

The position of the mouse cursor in the visible game screen can be checked by using the functions MouseX() and MouseY().

SetFPS 60
Do
    Cls 0
        Print "MouseX() : "
        Print MouseX()
        Print ""
        Print "MouseY() : "
        Print MouseY()
    Sync
Loop

Check if Mouse Cursor is In Area

Rectangle

The code below checks to see if the mouse cursor is located in a rectangular area.

SetFPS 60
Do
    Cls 0
        If MouseX() >= 200 and MouseX() <= 300
            If MouseY() >= 200 and MouseY() <= 300
                Print "Mouse in Rectangle"
            EndIf
        Endif    
        Box 200,200,300,300, True
    Sync
Loop

Circle

The code below checks to see if the mouse cursor is located in a circular area.

SetFPS 60
Do
    Cls 0
        If GetDistance2D(MouseX(),MouseY(),200,200) <= 30
            Print "Mouse in Circle"
        EndIf
        Circle 200,200,30,True    
    Sync
Loop

This page is a stub. You can help by expanding it.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.