1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML Difficulties when creating a pause menu with mouse

Discussion in 'Programming' started by royer14, Jun 24, 2018.

  1. royer14

    royer14 Member

    Joined:
    Dec 6, 2017
    Posts:
    25
    Hello how are you, as you have read the title, I have difficulties with this code:
    Code:
    if position_meeting(x,y,id) && mouse_check_button_pressed(mb_left)
        {
            if (global.pausee == 0)
            {
                global.pausee = 1;
                instance_create(x-60,y+120,obj_popup)
            }
            else
            {   
                instance_destroy(obj_popup)
                global.pausee = 0;
            }
        }
    this code is in the object called "obj_pause", step event, now when I start the obj_pause in the room, remember that I have 4 buttons on the screen.

    When I click the obj_pause, the screen is paused and everything is fine, but when I click somewhere else on a button different, it reacts as if I were pressing the obj_pause.
    What can be?
     
  2. dannerz

    dannerz Member

    Joined:
    Jun 21, 2016
    Posts:
    84
    with(obj_popup){ instance_destroy(); }
     
  3. Spencer S

    Spencer S Guest

    The only answer I can think of is that the collision mask is set incorrectly on the sprite that your button uses. I'd re-check that.
     
  4. royer14

    royer14 Member

    Joined:
    Dec 6, 2017
    Posts:
    25
    you refer to the destruction of the instance of the object, but as I do to create a button and when I click, the game is paused, but if I crush it again, the game resumes. My mistake is that when I click on any other part, the game is paused and when I click again, it resumes
     
  5. royer14

    royer14 Member

    Joined:
    Dec 6, 2017
    Posts:
    25
    I have not created a collision mask on that "obj_pause" object. I've tried but it still does not work.
     
  6. Spencer S

    Spencer S Guest

    The function https://docs.yoyogames.com/source/dadiospice/002_reference/objects and instances/instances/instance properties/mask_index.html should do the job for you. Just write:

    Code:
    obj_pause.mask_index = // sprite with a Collision Mask that has what you need
    The code above is for setting the Collision Mask of an object even if its using a different sprite, or none at all.

    To use the Collision Mask of the sprite that you have set for obj_pause, go into the sprite that you have set for obj_pause, and check to see that the Collision Mask is set to what you would like. Also, make sure that the Origin Point for that sprite is centered. Once you have done this, it should work without the above code.
     

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