how to make a button unclickable?

0 favourites
  • 13 posts
From the Asset Store
J-BoB Game Button Sound Pack comes with 300 high-quality sound effects
  • I have two buttons, each is a sprite. I have one directly on top of the other, in different layers. They are more or less one button for "on" and one button for "off". You should only see and be able to click on one of them at at a time - like a toggle.

    My first attempt I had them both in the same layer, and made one invisible by default (.e.g off). So the player only sees "on". When he clicks on the "on" button, I still get an onclick event on the off button, even thouh its invisible.

    So attempt two, I tried making the active button on a higher layer, and visible, and the inactive button on a lower layer, and invisible. However, both buttons still seem to get pressed.

    I see a few options:

    1) destry and create a new button each time one is clicked, so only one button is active at any time.

    2) Keep a button state global variable, and ignore the unwanted button events

    3) I could try and move the inactive button off screen to try and make it unclickable, but I dont know what affect this will have on the layout in a browser.

    I didnt see in the manual an explanation on how events pass down through layers. Has anyone seen such an article?

    Any suggestions?

    Many thanks!

  • I just tried option 3), but its not tennable.

    I need to swap the buttons over in many places. Its not going to be maintainable to duplicate the button location swapping code in every place its needed.

    As there are no custom events which can be triggered, the alternative is to create the construct 2 equivalent of a GOTO: include an event sheet. However, in a new event sheet, there seems to be no way to populate global variables with buttons X & Y coordinanets (i.e. the system event has no "set global variable" option.

    I could of course hard code the "off screen" buttons coords, but this wont lend itself to the many different screen sizes I'll need to support.

  • I'd go for option 2. Use a variable to check if a button is active.

  • ok you can use groups , for example group for making clickable and group for unclickable and so on... (by the way i didn't read your topic because i'm busy ^^)

  • Ok, I found a simple way to hack actions into a event sheet so I can use it as a GOTO - use a condition which is always true, e.g. System-> layer 0 is visible.

    So now I swap the button on the layout with the other botton way off the layout by including the swap script at the end of each buttons onclick event handling.

    But now I get the weirdest of behaviour: the newly swapped in button also gets clicked event!

    So I click once on an object, and in the onclick event for that object, swap the objects X&Y with a completely differetn object, and the new object also gets an onclick event, even though there has been no click on the second object.

    Is this a bug do you think?

  • use the same object and put the graphics of "on" and "off" state in frame 0 and 1

    on click on button -> set frame to 1-self.frame

    Also, layers are only a way to organise your sprite and another way of controlling z-ordering and also isolate some effects.

    In the end, as far as interaction and collision detection goes, it's just as if everything was in one layer.

  • ok you can use groups , for example group for making clickable and group for unclickable and so on... (by the way i didn't read your topic because i'm busy ^^)

    Thanks for the info, but how do grouping events (which I guess is just for readability?) help make objects not respond to clicks? In most programming languages, you would say object.enabled = false, but constuct 2 doesnt have this. Thanks, and sorry for beeing a complete beginner.

  • Be carefull I edited my last post (:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • for example you have 2 groups clickable, unclickable

    so on start of layout both of these are inactive groups.

    when player clicked on button (object)

    while clickable group is inactive then >> make group clickable active

                                            make group unclickable inactive

    when player clicked on button

    while clickable group is active then >> make group unclickable active

                                            make group clickable inactive

  • use the same object and put the graphics of "on" and "off" state in frame 0 and 1

    on click on button -> set frame to 1-self.frame

    Great suggestion.   I added a second frame to my on button graphic with the off button graphic. So now it has two frames.

    This:

       on click on onButton -> set frame to 1-self.frame

    says "frame is not an expression or instance variable in onButton"

    so I tried this:

    on click on onButton -> set frame to 1-self.AnimationFrame

    But now when I launch my game, it imedialtly jumps to the second frame, even though I havent clicked on anything, and the "initial frame" is set to 0.

    Is this normal? how do I stop it animating and runing through the frames on its own?

    I tried resetting the frame to 0 in the "on loading finished" and in the "on end of layout", but it still comes up showing frame 1 after the game has loaded for the first time. After thay, your frame toggle works fine.

    Any ideas?

    Thanks!

  • But now I get the weirdest of behaviour: the newly swapped in button also gets clicked event!

    So I click once on an object, and in the onclick event for that object, swap the objects X&Y with a completely differetn object, and the new object also gets an onclick event, even though there has been no click on the second object.

    Is this a bug do you think?

    Nah, it's just that when you click the mouse it will go through all the click events on the event sheet. It checks event 1, sees you've clicked on button 1 and then hides that button and moves button 2 into place. Then it checks event 2 and now button 2 is below the mouse so it counts as a click on it, even though it wasn't there when you first clicked.

    This came up before when someone wanted to show a box by clicking a button and then hide it by clicking on the box. The solution was to toggle a variable with the mouse clicks and then toggle the objects visibility based on the variable. You have to seperate it so the mouse clicks don't interfere with each other.

    toggleMenu.capx (r99)

    Yann's method is better for a toggle button.

  • If you edit the animations, is the animation speed 0? This will stop it from animating.

    It's so simple, but it something I forget to do more often than you would think! Haha...

  • I had the same problem as you. I have tried booleans, tried moving my buttons, tried even destroying it and creating it only when my popup was appearing... nothing worked!. I have found the 100% perfect solution that works perfectly(at least for me, who tried and tried and tried, worked):

    -Create a global variable called "time_until_popup_showed". It´s innitial value is -1.

    -When the popup should open(or a layer should be made visible), make the value of this global variable be 0.

    -In all conditions that have something to do with the button/image/object you dont want to be touched unless the popup is appearing, put the condition: "time_until_popup_showed > 0"

    -Make an event that is triggered every 1 second and time_until_popup_showed > -1 to make the global variable be added by 1(time_until_popup_showed will be time_until_popup_showed + 1)

    • If you made the user click somewhere (a button maybe) to open the popup/new layer, make this button invisible when you touch it(to make the popup open) and add this condition to its touch: button is visible
    • when you want to make the popup disappear, don´t forget to set the time_until_popup_showed to -1 and the button cited above(the one that opens the popup) to visible
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)