how to make a button unclickable?

Get help using Construct 2

Post » Sat Aug 18, 2012 10:55 pm

I have two buttons, each is a sprite. I have one directly on top of the other, in different layers. They are more or less one button for "on" and one button for "off". You should only see and be able to click on one of them at at a time - like a toggle.

My first attempt I had them both in the same layer, and made one invisible by default (.e.g off). So the player only sees "on". When he clicks on the "on" button, I still get an onclick event on the off button, even thouh its invisible.

So attempt two, I tried making the active button on a higher layer, and visible, and the inactive button on a lower layer, and invisible. However, both buttons still seem to get pressed.

I see a few options:
1) destry and create a new button each time one is clicked, so only one button is active at any time.
2) Keep a button state global variable, and ignore the unwanted button events
3) I could try and move the inactive button off screen to try and make it unclickable, but I dont know what affect this will have on the layout in a browser.

I didnt see in the manual an explanation on how events pass down through layers. Has anyone seen such an article?

Any suggestions?

Many thanks!

nutmix2012-08-18 22:57:26
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Aug 18, 2012 11:33 pm

I just tried option 3), but its not tennable.
I need to swap the buttons over in many places. Its not going to be maintainable to duplicate the button location swapping code in every place its needed.
As there are no custom events which can be triggered, the alternative is to create the construct 2 equivalent of a GOTO: include an event sheet. However, in a new event sheet, there seems to be no way to populate global variables with buttons X & Y coordinanets (i.e. the system event has no "set global variable" option.

I could of course hard code the "off screen" buttons coords, but this wont lend itself to the many different screen sizes I'll need to support.
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sun Aug 19, 2012 12:00 am

I'd go for option 2. Use a variable to check if a button is active.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Aug 19, 2012 12:20 am

ok you can use groups , for example group for making clickable and group for unclickable and so on... (by the way i didn't read your topic because i'm busy ^^)
B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Sun Aug 19, 2012 12:22 am

Ok, I found a simple way to hack actions into a event sheet so I can use it as a GOTO - use a condition which is always true, e.g. System-> layer 0 is visible.

So now I swap the button on the layout with the other botton way off the layout by including the swap script at the end of each buttons onclick event handling.

But now I get the weirdest of behaviour: the newly swapped in button also gets clicked event!

So I click once on an object, and in the onclick event for that object, swap the objects X&Y with a completely differetn object, and the new object also gets an onclick event, even though there has been no click on the second object.

Is this a bug do you think?
nutmix2012-08-19 00:24:37
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sun Aug 19, 2012 12:26 am

use the same object and put the graphics of "on" and "off" state in frame 0 and 1
on click on button -> set frame to 1-self.frame


Also, layers are only a way to organise your sprite and another way of controlling z-ordering and also isolate some effects.
In the end, as far as interaction and collision detection goes, it's just as if everything was in one layer.Yann2012-08-19 00:29:51
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Aug 19, 2012 12:27 am

[QUOTE=zsangerous] ok you can use groups , for example group for making clickable and group for unclickable and so on... (by the way i didn't read your topic because i'm busy ^^)[/QUOTE]

Thanks for the info, but how do grouping events (which I guess is just for readability?) help make objects not respond to clicks? In most programming languages, you would say object.enabled = false, but constuct 2 doesnt have this. Thanks, and sorry for beeing a complete beginner.nutmix2012-08-19 00:28:16
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sun Aug 19, 2012 12:30 am

Be carefull I edited my last post (:
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Aug 19, 2012 12:36 am

for example you have 2 groups clickable, unclickable
so on start of layout both of these are inactive groups.

when player clicked on button (object)
while clickable group is inactive then >> make group clickable active
                                        make group unclickable inactive

when player clicked on button
while clickable group is active then >> make group unclickable active
                                        make group clickable inactive
B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Sun Aug 19, 2012 12:59 am

[QUOTE=Yann] use the same object and put the graphics of "on" and "off" state in frame 0 and 1
on click on button -> set frame to 1-self.frame
[/QUOTE]

Great suggestion.   I added a second frame to my on button graphic with the off button graphic. So now it has two frames.

This:
   on click on onButton -> set frame to 1-self.frame

says "frame is not an expression or instance variable in onButton"

so I tried this:
on click on onButton -> set frame to 1-self.AnimationFrame

But now when I launch my game, it imedialtly jumps to the second frame, even though I havent clicked on anything, and the "initial frame" is set to 0.

Is this normal? how do I stop it animating and runing through the frames on its own?

I tried resetting the frame to 0 in the "on loading finished" and in the "on end of layout", but it still comes up showing frame 1 after the game has loaded for the first time. After thay, your frame toggle works fine.

Any ideas?

Thanks!
nutmix2012-08-19 01:07:17
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Next

Return to How do I....?

Who is online

Users browsing this forum: ETgirl79 and 12 guests