[SOLVED] Show and hide layer with same button

I found a thread about this from February 2017, but the solution won’t work for me. My events:

invIsVisible is set to false from the scene variables list.

The layer starts hidden (I set that from the layer panel), and I want the layer to reveal itself on pressing a button and hide again using the same button (toggle). I know it’s probably very simple, but I absolutely can’t get it to work.

If I disable the second sub condition, the first one works to reveal the layer. But if I enable it, the whole event fails to work. Many thanks in advance.

Hello,

This is because both conditions are being triggered at the same time. When the first action shows the layer, the second condition checks that the layer is visible then hides it again (or the opposite is happening)

Try using a toggle action, like the solution below:

2 Likes

You absolute star! That worked. Thank you! I hadn’t heard of the toggle boolean before. I am new to GDevelop, having started work on my first prototype just 4 days ago. But I am a bit annoyed with myself because I managed to make a simple inventory from scratch that remembers items between scenes… but I couldn’t work this simple layer visibility toggle out! Thanks again for taking the time to actually create the event to show me - I wasn’t expecting that. Very kind.

This happens a lot! I’m glad to help.

1 Like