The mouse is used for input and player control along with the keyboard.
Mouse Input
Mouse input has two different components, the mouse buttons and the mouse cursor.
Mouse Cursor
The mouse cursor is the image displayed to show you where the mouse is located on the screen.
Mouse Buttons
Checking Mouse Buttons
- mouse_check_button()
- mouse_check_button_pressed()
- mouse_check_button_released()
- mouse_last_button
- mouse_button
- mouse_wait()
Face the Mouse
Pro
You can make an object's sprite face (look at or point at) the mouse by changing the object's image_angle[pro] variable using point_direction().
This technique can be used to make a turret or other enemy face the mouse automatically.
// in step event
image_angle = point_direction(x,y,mouse_x,mouse_y);
This will only make the sprite face the mouse, it will not set the direction of the object to move towards the mouse. For this you should set the direction first and the image_angle second.
// in step event
direction = point_direction(x,y,mouse_x,mouse_y);
image_angle = direction;
Note that the object will not move if speed is set to 0.
Lite
Movement
Follow / Move Towards Mouse
See also Following.
Shoot Using the Mouse
There are two ways to "shoot" using the mouse. Which one you use will depend on the type of game you are making.
Shoot at the Mouse Cursor (2D Mouse Aiming)
To shoot at the mouse cursor
- Set the speed to the speed of the fired bullet.
- Set the direction of the bullet using point_direction(obj_bullet.x,obj_bullet.y,mouse_x,mouse_y);
Shoot With the Mouse (Mousehairs)
You can also shoot by using the mouse as gun sights to simulate light gun games. [info needed].
Related Pages
How To's
Reference
Actions
GML
Functions
- mouse_check_button()
- mouse_check_button_pressed()
- mouse_check_button_released()
- mouse_clear()
- mouse_wait()
Variables
All mouse variables are global variables
Links
| Categories: Input : Mouse |