0 Favourites

Touch Event hitting two objects

  • Hi all,

    I have items falling on screen, and when you tap on them you get -1 from your 'hit count'

    if you miss them and tap the background you also get -1 from your 'hit count'

    I have Touch Event setup for On Touch - ObjectA, and another for On Touch - Object B(background)

    When I tap on the background object there is no issue, but when I tap on the falling object, it registers the tap on both the object.

    These are on different layers if that makes a difference.

    I was trying to find a way to basically to do;

    Touch - If object = ObjectA then this, else this. But cant seem to find these conditions?

    Is there a smarter way I should be setting this up?

  • First thought (not tested)

    two variables gvScreenTouched and gvSpriteTouched

    on any touch start -- add 1 to gvScreenTouched

    (sub event)

    --touch is touching sprite -- take 1 from gvScreenTouched

                               -- add 1 to gvSpriteTouched

                               -- sprite destroy

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Would adding an is not touching objectA condition to the on touched objectB event work?

  • Would adding an is not touching objectA condition to the on touched objectB event work?

    Would I do that by using the 'invert' is touching sprite?

    if so it doesnt :(

  • Just do if (touching falling sprite) +0.. since you only want to subtract one, you're already subtracting one from the background. If you want to add 1 point for touching something else, go +2 to that object. I guess just offset everything by -1.

  • Just do if (touching falling sprite) +0.. since you only want to subtract one, you're already subtracting one from the background. If you want to add 1 point for touching something else, go +2 to that object. I guess just offset everything by -1.

    Yeah I ended up not doing -1 on hitting the Object A, works as intended now although prob not the best implementation

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