GML Difficulties when creating a pause menu with mouse

royer14

Member
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?
 
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.
 

royer14

Member
with(obj_popup){ instance_destroy(); }
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
 

royer14

Member
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.
I have not created a collision mask on that "obj_pause" object. I've tried but it still does not work.
 
S

Spencer S

Guest
I have not created a collision mask on that "obj_pause" object. I've tried but it still does not work.
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.
 
Top