How do I toggle a layer (flashlight) on/off?

0 favourites
  • 5 posts
  • The logic for this sounded very easy in my head. But I can't get it to work like I want (or at all for that matter).

    I want to create a flashlight that I can toggle on and off with the F key.

    I have the flashlight object set to invisible from the start.

    Here's the logic.

    --> Global number FlashlightOn = 0 (this represents 'off')

    Event 1 - If Flashlight is Off:

    Condition 1 - If FlashlightOn = 0

    Condition 2 - If 'F' key is pressed

    Action 1 - Set "flashlight" object to visible

    Action 2 - Set FlashlightOn value to 1 (this represents 'on')

    Event 2 - If Flashlight is On:

    Condition 1 - If FlashlightOn = 1 ("On")

    Condition 2 - If 'F' key is pressed

    Action 1 - Set "flashlight" object to invisible

    Action 2 - Set FlashlightOn value to 0 ("Off")

    Without the second event (which I have a feeling is unnecessary), I'm able to get the flashlight to turn on. But I'm not able to toggle it off afterwards.

    Here's the event sheet:

    <img src="" border="0" />

    Thanks for any help! I'm sure this is an easy thing to do. But I'm still new to C2!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • instead of the second event

    put the flashlighton = 0 as a subevent and

    use the system else condition.

  • instead of the second event use the system else condition.That was my first thought, but 'Else' is grayed out in the right-click context menu, and if I add it as a new event (or sub-event) it says "Else (not valid here)".

  • If you put it in the right place it will work, but well..

    create two events:

    system compare variable flashlighton = 0

    • flashlight set visible

    system compare variable flashlighton = 1

    • flashlight set invisible

    keyboard on f pressed

    • system set flaslighton : 1-flashlighton
  • Aha! That did it. Thanks a lot!

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