Interacting with menu buttons.
Setting a target location for a player.
Making a gun turret point in the mouse's direction.
Changing weapons.
Showing info on mouse over.
Moving a gun sight around the room.
trigger once when released
The mouse position (in a Desktop export) is updated at the frame rate (default of 60 frames per second).
mouse_x holds the current x position.
mouse_y holds the current y position.
Both of the preceding mouse variables are global in nature, and can be accessed from any instance within your game.
mb_left
mb_right
mb_middle
mb_none
mb_any
mb_middle means middle button
mb_none means no button
mb_any means any mouse button
Mouse interaction can also be detected and acted upon using Mouse Events, though you will have more flexibility using code.
This will make the instance move slowly to the mouse's position if the left button is being held down.
which will Increase the value of weapon by 1 when the mouse wheel is scrolled up.
which decreases the value of weapon by 1 when the mouse wheel is scrolled down.
Cursors
This will remain in place until to you set it to something else.
which sets the cursor to invisible – remember to set it back if it is needed.
which increases the score if the cursor is over any instance of obj_name – replace with id to check if it is over itself.
would check that the mouse is over itself and the left mouse button has just been clicked. A sound will then play.
Whether you use code or events, it is up to you and will change depending on what your game does.
Basic Projects
- A)
Make an object that moves accordingly to mouse x position (not y position).
- B)
Change the mouse's cursor when hovering over an object instance.
- C)
Display the mouse's position as text on screen.
Advance Projects
- D)
Set up various objects that each play a different sound when clicked.
- E)
Make an object that can be clicked and dragged around the room with the mouse.
Useful Functions
Summary
You should be able to add basic mouse interaction in your own games, and allow player interaction to be acted upon.