How do I handle button states

Get help using Construct 2

Post » Sat Apr 11, 2015 5:34 am

i have several buttons and i want the buttons to have several different states without having to' write' same code over again

my buttons are sprites btw

states are:
*enabled(btn sprite frame 1)/ disabled(sprite to frame 0)
*pressed/clicked(button sprite switches to to frame 2 for a few miliseconds)


is there any way to do this without having to 'write a bunch of code for each button?

i would like to be able to set btn1.disabled , and the software should automatically set the sprite to frame 0since im gonna have many buttons , i want to avoid writing this for every single button,is there a button plugin, that can help me out?
B
9
S
2
Posts: 76
Reputation: 709

Post » Sat Apr 11, 2015 5:37 am

You could put all your sprites in a family then you only have to code the events of what to do on touched
B
42
S
17
G
2
Posts: 850
Reputation: 6,209

Post » Sat Apr 11, 2015 5:38 am

Use Families. Add all your buttons to a Family. Add Family instance variables Enabled, Pressed/Clicked, etc. Also, add a 'callback' variable.

Use callbacks to automatically go to a section of code (call a certain function) when a particular is button is clicked.

Example:

On Touched "Button"
-- Call Function (Button.callback)
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053


Return to How do I....?

Who is online

Users browsing this forum: Bootfit, Construct Monkey, Freak Workshop and 23 guests