How do I block touch event through layers of object?

0 favourites
  • 11 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I have a game object for user to touch and destroyed.

    When it is cover by another obstacle, I want the obstacle to block the touch event, how can I implement this?

  • If sprite1 not overlapping sprite2.

    Or add a boolean variable to sprite1 and turn to false if is overlap the sprite2, then compare variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • what I do in similar situations is put all the objects in a family, and then when checking for touch, use the family and pick the top instance. Then if it is an obstacle, just ignore it.

  • If sprite1 not overlapping sprite2.

    Or add a boolean variable to sprite1 and turn to false if is overlap the sprite2, then compare variable.

    Thanks. If I have sprites that has irregular shapes? Can I detect the touch based on the collider?

  • what I do in similar situations is put all the objects in a family, and then when checking for touch, use the family and pick the top instance. Then if it is an obstacle, just ignore it.

    Thanks. Can you show me an event sheet example of how to implement this?

  • here is a quick sample:

    I gave the family an instance variable to tell the objects apart, but there are other ways too...

    https://rieperts.com/games/forum/PickTop.c3p

  • here is a quick sample:

    I gave the family an instance variable to tell the objects apart, but there are other ways too...

    https://rieperts.com/games/forum/PickTop.c3p

    Thanks for the example that's very clear.

    I have some irregular sprites like the cloud covering the factory below

    Do you have any idea on how to detect the touch "through" the empty parts of the clouds?

    I checked the collisions mask but it seems it wont be used for touch detection.

  • that would be a pretty complicated collision mask... but it should work.

    an alternative would be to make simpler cloud shapes, and then combine several to make up a cloud that looks like that - an if you randomise it, you could get different clouds each time.

  • that would be a pretty complicated collision mask... but it should work.

    an alternative would be to make simpler cloud shapes, and then combine several to make up a cloud that looks like that - an if you randomise it, you could get different clouds each time.

    I found the problem, somehow the collision mask are not correctly set. So the clouds are getting a full rectangular collision box...

    Combining with your solution it works perfectly now.

    Thanks again for everyones help.

  • that would be a pretty complicated collision mask... but it should work.

    an alternative would be to make simpler cloud shapes, and then combine several to make up a cloud that looks like that - an if you randomise it, you could get different clouds each time.

    If I have multiple instance of the factory objects in my screen, how can I reference only the one that I touch in my actions?

  • You can use "On touched object -> FactoryObject". That will pick only the factory you touched (as long as they don't overlap). Action after that will only apply to that one. If you need to remember after the touch event, then store the UID of that factory in a global variable, which you can later use to pick just that one factory.

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