1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Help with mouse released event.

Discussion in 'Programming' started by hiep, May 17, 2019 at 2:41 PM.

  1. hiep

    hiep Member

    Joined:
    Apr 30, 2019
    Posts:
    41
    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 !
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,788
    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 [​IMG], right [​IMG] and middle [​IMG] 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.
     
    hiep likes this.
  3. hiep

    hiep Member

    Joined:
    Apr 30, 2019
    Posts:
    41
    I have set collision mask to full image but it still not running.
     
  4. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,788
    You should post your code.
     
  5. hiep

    hiep Member

    Joined:
    Apr 30, 2019
    Posts:
    41
    its only 1 line in left realeased
    grab = false;
     
  6. hiep

    hiep Member

    Joined:
    Apr 30, 2019
    Posts:
    41
    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 ?
     
  7. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    515
    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.
     
    hiep likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice