How do I Prevent Click Through Object [Solved]

Get help using Construct 2

Post » Thu Jun 22, 2017 12:56 pm

Dear,

I want to build a confirmation dialog as player click on a Reload button (I call it layer A - Show picture with Exit, cancel buttons) to return 1st layout.

Do you know how to prevent click through layer A (prevent affect items clickable under layer A)?

Thanks!
Last edited by gianghl1983 on Fri Jun 23, 2017 1:50 am, edited 1 time in total.
B
24
S
4
G
1
Posts: 27
Reputation: 1,724

Post » Thu Jun 22, 2017 1:11 pm

I personally use a finite state machine for this. Basically you have a global variable that changes depending on the current state of your app. In your case you have two states, the "normal" state and the "confirm_dialog" state. Once the confirm dialog shows you change the global variable to "confirm_dialog" and check the condition of the variable.

Image

http://gameprogrammingpatterns.com/stat ... the-rescue
B
16
S
3
Posts: 69
Reputation: 1,048

Post » Thu Jun 22, 2017 1:18 pm

Thanks! However this is could not be applied to my game due to its complicated (could not control with only 1 variable SWITCH).

I need to learn how to make anti-click through objects in Construct 2!
B
24
S
4
G
1
Posts: 27
Reputation: 1,724

Post » Thu Jun 22, 2017 1:18 pm

Just add a condition on the buttons on the layer under the active layer.

For example:

On button Pressed ------------> do something
layer A is not visible

Add a regular "layer is visible" condition and right click on it and invert it or press "i".

You can also do the same on the events for the buttons on layer A but they should of course just work when layer a is actually visible.

Image
B
55
S
24
G
13
Posts: 766
Reputation: 12,573

Post » Thu Jun 22, 2017 1:33 pm

@Anonnymitet: I understand that by using toggle layer vissible/invisible I can toggle a dialog (layer A). However, what I want is prevent click through this layer (layer A display at center of current game screen)...
B
24
S
4
G
1
Posts: 27
Reputation: 1,724

Post » Thu Jun 22, 2017 1:38 pm

As I said, you should set a condition to all buttons to make them not clickable when they are not in focus. There are tons of ways to prevent that. But the way I showed you should work just fine.

So on the buttons that you don't want to be clicked under layer A. Give those a condition that makes them only clickable when layer A is NOT visible and they can not be clicked under your dialogue box :)

Image
B
55
S
24
G
13
Posts: 766
Reputation: 12,573

Post » Thu Jun 22, 2017 2:06 pm

@Anonnymitet: Thank you! I do not understand you clearly on the previous comment. It is what I need!
B
24
S
4
G
1
Posts: 27
Reputation: 1,724

Post » Thu Jun 22, 2017 2:16 pm

No problem, glad you got it working. Good luck with your project :)
B
55
S
24
G
13
Posts: 766
Reputation: 12,573

Post » Thu Jun 22, 2017 6:21 pm

For the windows in my project I am using a system that requires one global variable - window_Level, and an instance variable window_Level for every object (buttons, images etc.) that I am displaying in windows (add them in a family and make one instance variable for all).

So, every time you open a window, raise the global window_Level by 1 and set the instance variable window_Level to the new level for all objects of that window.
Once you click a button, check if the button instance variable is equal to the global.

Also, don't forget to reduce the value when closing a window.
My first project:
Image
B
20
S
8
G
1
Posts: 172
Reputation: 2,463

Post » Thu Jun 22, 2017 11:05 pm

@RobertMKD: Great approaching method! Thank you! ;)
B
24
S
4
G
1
Posts: 27
Reputation: 1,724


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests