How do I stop an invisible layer from registering clicks?

1 favourites
  • Hi,

    So it seems that invisble layers in my game register touches/clicks all the same.

    Can I prevent it?

  • Your could ad "Is Visible to the "on Click" conditions.

  • Unfortunately this doesn't cut it.

    The two layers have buttons at the same places so it quickly becomes messed up when I click a button, the upper layer appears and immediately registers the same click.

    I think there should be a live 'locked' property for layers or something like that.

  • In fact, here's a *.capx.

    As you can see, the touch registers for the first event, then it meets another condition and is registered again for the second event.

    I'm not sure how would i go around it.

    Also, a simple 'else' might solve it in this example because it is very simble but in my project I have like 100 entangled events and 15 layers so it won't do the trick.

  • And here's a solution, if anyone's interested. This way the touch is registered only once instead of twice. The problem is still that it is a bit hacky... Relying on the order of events in C2 never seemed too elegant to me. Anyway, if anyone's got a better idea please let me know.

  • For some reason I cant download them. Create a global variable "Layer_Name_Is_Visible " Set the value to 0.

    When the layer goes invisible change the value to 1.

    Add the following condition to mouse click condition:

    System > Layer_Name_Is_Visible =0

    Mouse > on objects clicked

  • Hi! it's a pity you can't download the attachments. As I've said I already solved the problem but just for the sake of clarity here's why the 'isVisible' condition won't work in this case:

    As you can see the upper layer stays always invisible (or stays always visible if I switch the conditions).

  • If your buttons are sprites you could try disabling collisions on them when the corresponding layer becomes invisible

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • another example...

    [attachment=0:1sgzt8hd][/attachment:1sgzt8hd]

    And another way is you can also add buttons functionality to groups and enable/disable groups.

  • DUTOIT

    monitz87

    I don't think collisions affect clicks but I might be wrong. Disabling groups will be subject to the same problems as in the picture in my previous post. I've tried that. But I will have a look at this .capx!

  • DUTOIT

    monitz87

    I don't think collisions affect clicks but I might be wrong. Disabling groups will be subject to the same problems as in the picture in my previous post. I've tried that. But I will have a look at this .capx!

    Actually, after I posted my reply I had the same question: "do touch events take hitboxes into account or the actual sprite image?"... I think it is worth testing at least.

    Groups should be different because you can put all the events involving a certain layer into a group, and disable said group when its associated layer is invisible, so you won't get those 'my click triggered events on various layers' problems, because all events on an invisible layer would be disabled.

  • pirx, Yes collisions affect clicks - lol. That is the hitbox as monitz87 says. But it isn't a solution as you usually want the whole button to be clickable.

    Groups work, it just isn't the best way to do it. I used it on a previous project, but it takes some out the box thinking.

    The capx I posted is a nice work-a-round. There are other ways too - lots of ways, actually.

  • pirx, Yes collisions affect clicks - lol. That is the hitbox as monitz87 says. But it isn't a solution as you usually want the whole button to be clickable.

    I never suggested altering the button's collision polygon, I just said he should disable collisions on buttons which belong to invisible layers (and enable them when the corresponding layer becomes visible), so they don't register "On Click" events, which would basically solve his problem.

  • > pirx, Yes collisions affect clicks - lol. That is the hitbox as monitz87 says. But it isn't a solution as you usually want the whole button to be clickable.

    >

    I never suggested altering the button's collision polygon, I just said he should disable collisions on buttons which belong to invisible layers (and enable them when the corresponding layer becomes visible), so they don't register "On Click" events, which would basically solve his problem.

  • Hi. I tried to disable collisions for the invisible layers but it seems they are still blocking a click on the current layer. o.O (r176)

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