Tai Christian
Tai Christian

Reputation: 665

GameMaker Studio mouse click event goes wrong?

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

Answers (4)

MarmouCorp
MarmouCorp

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

Timtech
Timtech

Reputation: 1274

You did:

  • button_1: event mouse left button -> destroy itself and create object button_2 at same position
  • button_2: event mouse left button -> destroy itself and create object button_1 at same position

Your mistake:

  • Event should be "Left Pressed", not left button

I also recommend:

  • Create the new instance before you destroy the old one

Upvotes: 0

Dmi7ry
Dmi7ry

Reputation: 1777

Use mouse_clear(button) in the button, like

mouse_clear(mb_left);
instance_create(x, y, button_2);
instance_destroy();

Upvotes: 0

Fill Freeman
Fill Freeman

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

Related Questions