1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Click not working on no-sprite obj_titles.

Discussion in 'Programming' started by MrHarlan, Nov 22, 2017.

  1. MrHarlan

    MrHarlan Member

    Joined:
    Nov 22, 2017
    Posts:
    3
    Greetings!

    I am trying to create an interactive titles object that detects what room it's in, shows appropriate titles on the screen through a draw text action, changes a variable based on the point_in_rectangle function, and finally on the left mouse pressed event executes a command based on the selection variable.

    The left mouse pressed event isn't triggering. If I switch to the enter key pressed event, it works fine.

    Does the left mouse pressed event require that the obj has a sprite, and thus it's really detecting click_in_hitbox?

    I'm pretty sure I could just move the event into the step event and have an if look at whether the mouse is currently being clicked, but I was using the separate events to reduce clutter. My step event will probably get very bulky as I reuse the object for different rooms.

    click event works as an enter key pressed event:
    click event.png

    step event sets option variable based on mouse position:
    step event.png
     
  2. BattleRifle BR55

    BattleRifle BR55 Member

    Joined:
    Jun 24, 2016
    Posts:
    976
    The Mouse events are indeed tied into the object's mask.
     
  3. MrHarlan

    MrHarlan Member

    Joined:
    Nov 22, 2017
    Posts:
    3
    Thank you for your rapid response. I was afraid that was the issue, but wanted confirmation tomake sure I hadn't created a glitch.
     
  4. ParodyKnaveBob

    ParodyKnaveBob The Laughing Rogue

    Joined:
    Jun 23, 2016
    Posts:
    537
    Howdy, MrHarlan, and welcome to the GMC! $:^ J

    If you intend to check point_in_rectangle anyway, you should probably be able to very simply highlight your event, click the [Change] button (or GMS2 equivalent if you're there), and tell the Left Mouse Button Pressed Event to instead be a Global Left Mouse Button Pressed Event. $:^ J

    I hope this helps,
    Bob
     
  5. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    Yep you'll need to move that into the step event, define the rectangle clicked in, and to avoid clutter you can make a script and have each object that uses it call it with it's own argument value, so in the script you can do different things and put the bulk of your code there divided up into argument values depending on what argument value was given.
     
  6. ParodyKnaveBob

    ParodyKnaveBob The Laughing Rogue

    Joined:
    Jun 23, 2016
    Posts:
    537
    No, seriously, MrHarlan doesn't need to move stuff from his Left Mouse Button Pressed Event to the Step Event. He can continue to use separate events to reduce clutter. I already posted this:

    ...but let me clarify in case there's any doubt. I inferred before, but now I'm looking at the screenshots he posted, and yes, he uses (GMS2 and) point_in_rectangle() to determine where the mouse is when the user clicks. When not using the built-in sprite mask functionality, one must use the Global Mouse Events to affect anything. Therefore, since the event (for local mouse interaction) already exists as we see coded, there's no need to even move the code. All one has to do is (~checking the GMS2 manual right now since I still haven't actually used it~) right-click that "Left Pressed" Mouse Event, then select Change Event from the context menu, and finally choose "Global Left Pressed" Mouse Event. Presto, now the object's instance fires that Mouse Event with any click, then checks the aforementioned point_in_rectangle() to see where it matches. (Btw, while looking through the manual, I see there's a new "Tap" Gesture Event alternative, but it might be overkill in this case, I don't know.)

    Regards,
    Bob
     
  7. Dengar

    Dengar Member

    Joined:
    Jun 21, 2016
    Posts:
    285
    A cheap workaround. Give the object a sprite and then in the draw event just put a comment. Thatll give u a mask but the sprite wont be drawn.
     
    Wraithious likes this.
  8. MrHarlan

    MrHarlan Member

    Joined:
    Nov 22, 2017
    Posts:
    3
    Thank you both. I was able to solve this problem with the global left mouse pressed event. (If anyone is looking for it in GMS2, it's at the bottom of the list of mouse events, there's a submenu of global mouse events.)

    The next issue with this same set of code is that the "Do you really want to quit" dialog pulls the program out of fullscreen, which is visually unappealing. Is there a full-screen friendly version of the dialogue question method that wouldn't include me creating an entire interactive element?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice