Search code examples
mouseeventgame-maker

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!


Solution

  • 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.