How do I Prevent Piercing zindex on a touch event

Get help using Construct 2

Post » Mon May 05, 2014 3:35 am

I am new to C2 with a programming background and I am baffled on this one.

I am developing a strategy game that records accuracy of touches.

I have a large object in the background and a smaller object in the foreground.

The background object has a z-index of 0 (sent to bottom of layer). The foreground object has been sent to the top of the layer.

When I click the object in the foreground, it executes the on touch event for both my foreground object AND the object at the bottom of the layer.

Based on z-index, I am only expecting the foreground object to register a touch when it has been accurately selected. The background object should only register a touch on misses.

Thanks in advance!
B
3
Posts: 3
Reputation: 181

Post » Mon May 05, 2014 4:34 am

Technically, if there are only the 2 options, touch the object, or touch the background, you could remove the on touch event for the background object and have a single on any touch event. This event would have a sub event for touching the correct object and an else sub event to handle anything else. This would remove any possibility of the on touch happening on the background object.

If this is not the intended result, you could add a condition to your background on touch event that says not touching the object.

I hope one of these suggestions works for you and good luck with your project.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Mon May 05, 2014 4:40 am

Thanks for the insight! The second option sounds the cleanest - I'll give that a shot. Cheers!
B
3
Posts: 3
Reputation: 181

Post » Mon May 05, 2014 4:55 am

@rwcatalano

Glad I could help. As for your response saying option 2 sounds cleanest, I just wanted to float an example of option 1 your way:
SingleOnTouchEvent.PNG


The image is all it takes to do option 1. I have included the cap so you can see it work.

Not saying to change. The second option should work just fine for you and be more appropriate in your project. I'm just pointing out that the first suggestion is actually much more clean and compact.
You do not have the required permissions to view the files attached to this post.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Mon May 05, 2014 1:47 pm

Fantastic! Very clean indeed. Thanks for the cap file reference as well!
B
3
Posts: 3
Reputation: 181


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 13 guests