Reputation: 665
I have used Gamemaker Studio for several months, but still learning it. Today I meet trouble with the mouse click action:
I have 2 objects called button_1 and button_2. My main purpose is that when a player clicks on button_1, it will be replaced by button_2, then clicks on button_2, it will be replaced by button_1.
So I did like this:
button_1: event: mouse "left button" -> destroy itself and create object button_2 at the same position
button_2: event: mouse "left button" -> destroy itself and create object button_1 at the same position
However, when I click on the button_1, it show the button_1 immediately. I guess the problem is caused by the position because when I put 2 buttons far from each other, it's okay, but if they overlap, problem appears on the shared area.
Have you ever faced the similar problem? Any idea to fix it?
I am learning English, please forgive me and ask if my explanation is not clear. Thank you in advance!
Upvotes: 1
Views: 5242
Reputation: 1663
As mention by other you should use the "Left Released" event instead of "Left button".
Moreover you should check thaht you only have on instance of the same object at the same place in the room. I was having the same problem (multiple click event fired) and it was cause by 2 or more object stacked each trigerring an event.
Upvotes: 0
Reputation: 1274
You did:
Your mistake:
I also recommend:
Upvotes: 0
Reputation: 1777
Use mouse_clear(button)
in the button, like
mouse_clear(mb_left);
instance_create(x, y, button_2);
instance_destroy();
Upvotes: 0
Reputation: 199
Try using the "Left Released" action instead of "Left button".
I found that the "Left button" action triggers three times at a time, so I prefer using the "Left Released" action, because it triggers only once.
Upvotes: 3