How do I show and hide?

0 favourites
  • 6 posts
  • Hello,

    hello I want to ask how when we click button A and image A will appear and when we click button A again it will hide image A

  • You could use a variable to toggle the on/off. You could use on button clicked : toggle boolean, where the boolean is an instance variable on the image object. Then you would have other conditions if object.boolean=true set visible, if object.boolean=false set invisible. Clicking the button then changes between true and false or visible/not visible.

  • touch/click executes very quickly.

    If you have issues, try putting a "wait: 0.1" seconds on the touch end.

    (just putting this out here to help others too)

    Not your exact situation but a common variation of your question.

    touch start, set sprite.scale=0.9 and sprite.var_touch = 1

    On "any touch end" AND

    "touch is touching" the sprite, set scale to 1 and var_touch 0, wait: 0.1s and execute your code.

    else set scale 1 and var_touch 0

    Gives the user some feedback (shrinking, expanding, etc) and allows for smooth transitions.

    The only other tip I might add, in places where it is critical the button is only pushed once, I've found it's best to delete the button instantly upon touch end then execute (and if there is only one of that sprite check the sprite.count to be doubly sure. etc etc)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could use a variable to toggle the on/off. You could use on button clicked : toggle boolean, where the boolean is an instance variable on the image object. Then you would have other conditions if object.boolean=true set visible, if object.boolean=false set invisible. Clicking the button then changes between true and false or visible/not visible.

    can you make the code I am confused when I understand it. sorry because I'm learning to use construct

  • dropbox.com/s/x6bhe1qfsivob82/visible%20sprite.c3p

    thank you very much it really worked

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