1
\$\begingroup\$

I've been making my first, simple game in Game Maker. You have to click a moving ball (obj_ball), each time you click it, it wil start moving faster. I wanted to add a way to lose the game: if you would miss a ball, it would redirect you to another room. I tried creating a new object (obj_gameover) covering the whole backgroud and adding a 'left pressed' event with a proper execute line to it, but whenever I click on a obj_ball, it also clicks on a obj_gameover, executing events from both objects. Is there any way to fix my problem?

\$\endgroup\$
  • 1
    \$\begingroup\$ holy misleading title batman, I'm gonna edit it \$\endgroup\$ – jhocking May 31 '17 at 20:37
1
\$\begingroup\$

You could check in obj_gameover whether the ball is clicked too or not. Something like:
Left Pressed (obj_gameover):

if (!obj_ball.clicked)
{
    // proceed your obj_gameover's onclick actions
}

Where clicked is the variable in obj_ball, which becomes true in obj_ball's Left Pressed, and becomes false in Step Event.

HOWEVER
I would like to suggest you to implement your system in a differeny way, without the giant obj_gameover. Use something like this in obj_ball's Step Event:
Step Event (obj_ball):

if (mouse_check_button_pressed(mb_left)) // if button is pressed...
    if (instance_position(mouse_x, mouse_y, obj_ball) == id) // if cursor is on object
    {
        // do all the actions you currently do in Left Pressed Event
    }
    else
    {
        // mouse is pressed, but cursor is not on the ball
        // do your gameover actions
    } 
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Use something like this in obj_ball's Step Event: not Step but Step End for avoid lag. \$\endgroup\$ – Dmi7ry Jun 1 '17 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.