How do I make the left mouse click to set this animation?

0 favourites
  • 2 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. With wood, nature, & jungle theme
  • I'm learning how to use construct 2 to make a point'n click game.

    What I want to make is: a door, With the cursor over the door it gets highlighted,and when we right click on the door you can see three option,(open, knock and kick) they are highlighted when the cursor is over them as well, when you click in the "open" option with the left button click, the door gets open (WOW). The problem is, i'm stuck in the part where I click in "open" and the door simplt doesn't do nothing. What am I doing wrong? I will let a video explaining what I tried to do:

    [youtube video="
    Subscribe to Construct videos now

    "]

    I am using the free version of construct 2 , not sure what version.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi pirulitao,

    I think I see what the problem is. So a lot of events are checked every tick, or every 1/60 of a second. This includes your first two events: 1. Is the mouse over the door? and 2. Is the mouse not over the door? Basically, every sixtieth of a second, the computer is looking for where the mouse is.

    Now compare that to your "Click on the door" event: it is a triggered event. Notice the green arrow next to the event that the "mouse hover" events lack. This means that it is looking for the click, and only then will that event fire. Once it does, it's done until the next mouse click.

    Finally, rethink about how events are thought of: every sixtieth of a second, the events sheet goes down the list, top to bottom, checking each event and then making an action if any event is true.

    So! The instant you click on "Open Door," the three events in question fire in their order: Is the mouse hovering over the door? Then, is the mouse not hovering over the door? (One of those will always be true while the other is false) Then, did the mouse click "Open Door?" True! Set the animation to Door2 (the open door animation). This is good!

    NOW, the next tick (1/60 of a second later), the sheet cycles through the events again: Is the mouse hovering over the door? Then, is the mouse not hovering over the door? Note that one of those will always be true! So one of those events will trigger, and the door animation will flip to either closed or highlighted. Then, did the mouse click "Open Door" this tick? It didn't! It did last tick, but not this one, so that doesn't fire.

    Hopefully this makes sense: with your current code, you get the desired open door for 1/60 of a second before it resets itself.

    To fix it, I think you should add a global variable! Name it something like "doorOpen," keep it as a number, and then when you are checking the mouse hover (your first and second events), also check if doorOpen is 0. When the mouse clicks on "Open Door," set the animation like you have, but then also set the variable doorOpen to 1. Finally, add another two actions to that event: first, Wait 1.0 seconds, and then set the variable doorOpen to 0. Both the set global variable and Wait actions are in System. All in all, this should set the door to Door2 animation for 1 second, and then close it again.

    Hope this helps! Let me know if you have any more questions.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)