How do I Prevent Piercing zindex on a touch event

0 favourites
  • 5 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • 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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Thanks for the insight! The second option sounds the cleanest - I'll give that a shot. Cheers!

  • 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:

    [attachment=0:1npriaet][/attachment:1npriaet]

    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.

  • Fantastic! Very clean indeed. Thanks for the cap file reference as well!

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