Toggle button an its actions

  • Hello, mates.

    What's the best way to do a toggle button? The methods I've tried these past days doesn't seem to work and it's so annoying...

    I want this:

    · In the scene, there is a character.

    · If the player touches the button > The sprite (state) of the button change, the actual character dissapear and appear another at the same position of the initial character.

    · When the player touch the button again, it's the same process, but the other way around. So the button have two states and there are two characters to alternate.

    · There are two classes of objects during the game. Character A can collect only object A and character B, only object B.

    What's the best way to do this? I'm confused, because I don't understand why my methods have failed.

    Also, another simple doubt:

    I've set an action when the player touches any area of the screen, but I don't want to activate this action when an UI button is touched. I only want to activate the button action. How could do this correctly?

    Thank you for your help!

  • Can you upload something clear about your problem ? A screenshot or a capx.

    In my opinion, you can add a boolean for your button.

    When you touch it -> action is toggle boolean

    Then you compare that boolean and do the action for your characters.

  • Maybe you can play an animation and move the character to the ousite from the layout, when the sprite is touched, and move the other character to this position. Or you destroy and create the character new at the last position. Or you switch the animation frame, when all in one sprite. Then you need to detect, which character is or is not on screen, that you can set the animation or move the character when he hit the sprite.

    The other part depends on how you progammed the game.

    You can set the objects to collision disabled, when charakter a is not on screen.

  • Thank you for your answers, Maverick1912 and Killax11. I really appreciate it.

    Maverick1912, here is the concept I'm working at: https://mega.nz/#!IVFGQYwD!iuOq3rM3i2Qt4NDXOPoO7uMfk3Vp2DxZoSWbEXLtdYk

    I'm a begginer and I think is so easy, but I don't understand why it's failing trying it using the methods that Killax11 have mentioned... I've tried these past days all of that ways to make it work, but there is always a problem.

    And the problem with the touches on the button, which makes characters to jump is so annoying too. How can I solve it? (the invisible sprite I created for a "jumping activator" doesn't work).

    I hope you can help me! Thank you!

  • Miguel Romo I have corrected your CAPX you can download from

    my dropbox file name Demo Example.capx

    cgpatel.co.uk

    or check your code

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Miguel Romo I have corrected your CAPX you can download from

    my dropbox file name Demo Example.capx

    cgpatel.co.uk

    or check your code

    Thank you for your time, Lordshiva1948, but I can't find the file you mention in your Dropbox directory.

  • Miguel Romo check again it's there File Name: Demo Example

  • Miguel Romo check again it's there File Name: Demo Example

    Thank you for your help, Lordshiva1948. I'm checking your modified file, but it still having bugs. Is it that complicated to make it work? It seems to be harder than I thought...

    Update:

    It seems that I finally got it, although the characters change their positions when I touch the button to make them appear/disappear and that causes some "oddities" in the game...

    And the problem with jumps persist. I've set an action when the player touches any area of the screen, but I don't want to activate this action when an UI button is touched. I only want to activate the button action. How could do this correctly? I thought Construct 2 respected the Z order when you touch or make click on the UI or another element of the screen.

    If the characters jump when any region of the screen is touched (one tap), how could I do to assign a double tap to change between the characters without conflicts with the number of taps?

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