• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with mouse released event.

H

hiep

Guest
Can anyone tell me what exact the mouse released event do ? i have left click in object then released but the code in mouse released event not running.

Thanks for advance !
 

samspade

Member
Can anyone tell me what exact the mouse released event do ? i have left click in object then released but the code in mouse released event not running.

Thanks for advance !
mouse release or global mouse release? Both events need the specified mouse button to be released. Global will trigger any time that mouse button is released, non global will trigger only if the mouse is currently 'colliding' with the object which means that the object needs to have a valid mask (which by default any object with a sprite would as defined in the sprite editor).

Remember to read the manual as well.
https://docs2.yoyogames.com/source/_build/2_interface/1_editors/events/index.html

The left
, right
and middle
button events (whether normal, pressed or released) all work on the mask of the instance that has the event. What this means is that GameMaker Studio 2will check the position of the mouse in the room when those buttons are used against the collision masks of the instances that have a mouse event. If there is a "collision" then the event will be triggered, so make sure that any instance with these events has a sprite with a valid mask or that the object has a mask selected in the object properties. As their names imply, these events will be triggered either once when the chosen mouse button is first pressed or released, or continuously each step while the button is maintained.

The mouse enter and leave events are also similar to the button events in that they too rely on the mask of the instance to work, but this time they are triggered when the mouse first "enters" (touches) the instance or when the mouse "leaves" (stops touching) the instance. These events are not continuous however, and are triggered only once for each time the mouse enters or leaves the object - so they are an ideal method for creating, for example, buttons that need to change as the mouse hovers over them before going back to normal when the mouse is removed.

Finally we have another section to the mouse events which is called the Global Mouse. In this sub-menu you will find a selection of events that are for recording mouse events in instances even when the mouse is not over them or even near them. These are events that are generated for all instances and if there are actions or code defined for the specified event then it will be run, regardless of the position of the mouse within the game room.
 
H

hiep

Guest
I have set collision mask to full image but it still not running.
 
H

hiep

Guest
I find the solution but i think something is wrong.

I copy the code in left released to step event with :
Code:
if (mouse_check_button_released(mb_left))
{
    grab = false;
    clicked = false;
}
it work ?

What is different here ?
 
H

Homunculus

Guest
The last code runs globally, it happens every time you release the mouse is released and for every instance of that object, so it does indeed work, but it’s not executed on the dragged instance only.

The left released event happens only if the mouse is over the instance collision box. If you are moving the mouse faster than the game can move the instance, when you release the button the two may not overlap, and therefore the code will not run.
 
Top