Simple button toggle?

0 favourites
  • 6 posts
From the Asset Store
Toggles Dials Switches and Alerts ! A foundational sound grouping of Analog type switches and Steampunk effects
  • This may be a silly question but I've never been able to figure out a quick and effective way to do this:

    Let's say I want to toggle a sprite from visible/invisible with a single button press. How do I accomplish this, preferably without flags or values, in simple and clean way?

    What I usually start with is something like this:

    Button is pressed

    -Sprite is visible -> set invisible

    -Sprite is invisible -> set visible

    I understand why it doesn't work as I want it to and why the bottom child event is what we end up with, but sure would be nice if it did sometimes :D

  • Use the Toggle option when setting the visibility of the sprite.

  • Thank you that would solve it, though I used a bad example, sorry; What if it was toggling between two animations instead?

    It's something I like to use when debugging my game.

    Press button when Effect 2 -> Effect 1

    Press button when Effect 1 -> Effect 2

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If I understood what you said.. you just need an else.

    Button is pressed

    -Sprite is visible -> set invisible

    ELSE

    -Sprite is invisible -> set visible

  • Else! It worked! Thanks!

  • If you want to toggle effects, I am afraid there is no "simple" way of doing it. It is not terribly difficult, but you will need to do a few extra things asides from toggling a variable.

    Here is how I would attempt to do that.

    dropbox.com/s/ujxik0hl3trlfu9/ToggleEffects.c3p

    The project has two functions, ToogleEffects and ToggleEffects2.

    ToogleEffects is the generalized case, you can send in a "main" effect and a list of the other effects in the instance you are targeting and the function takes care of enabling and disabling effects according to an instance variable.

    ToogleEffects2 is conceptually the same as ToogleEffects but it has all the names for the effects it can handle hardcoded in it, it's easier to understand what it is doing, but less useful.

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