How do I differentiate two or more touch inputs?

0 favourites
  • 14 posts
From the Asset Store
Supports keyboard, mouse and gamepads. Supports several gamepads at once.
  • Hi at All

    We have the problem that we can't differentiate two or more touch input to control our player and shoot at the same time. Now we make a test capx with the player controls on the yellow background. That's work fine but when u touch on the white screen to simulate the second touch or switch the touch inputs the player doesn't move anymore because he couldn't differentiate between the two touch inputs.

    Can U help us?

    Capx Example:


    Planlos Studios

  • If I understand what your looking for...

    The code will only run on the touch that is touching the yellow bit. (Works on my multi touch screen, so should work on mobile)

    This is a simple version, but should work for what you need.

  • Hello

    No that is not i looking for.

    We want a movement with the left finger on the yellow bit and with the right finger tap or hold at a button (white bit) to shoot. The Problem is the sequence of the touches. The player should only move when the left finger is on the yellow bit but on the same time can be the right finger on the white bit. It must be differentiate which finger is on the yellow bit that we can say take only the position from the left finger for the player. The Player should only move on the own position with the same angle and speed like the left finger.


    Planlos Studios

  • Each individual touch is given a separate touch ID, so you can differentiate them by their ID.

  • Hey Ashley

    Please have a look at my Capx. I think the problem is the touch (0) or (1). This doesn't work like i want. he only check the touch (0), i don't understud what construct touch(1) do.

    Can u explane me what the mistake is between touch (0) and touch (1) in my Capx.


    Planlos Studios

  • If you use what I gave (and add one "if isn't touching object") you should be able to make it work...

  • LoseBiene

    Multi touch get pretty tricky, and there is no way to know how many fingers a player may try to put on the screen, so it is best to track all touches and decide what each one is allowed to do.

    I like to create a sprite called TouchPoint that has all the instance variables I need to track the touch - where it started, where it is now, where it just was, how long it has been in touch, etc...

    I made two global variables: PlayerTouchPoint and GunTouchPoint to lock control of the player and firing the gun to one TouchPoint instance. That way, if the player isn't watching where their finger is, the same touch will keep doing what the player wants it to do.

    so, this will work with any number of touches starting and stopping, but only one at a time can control player movement, and firing the gun.

    NOTE: I always have a HUD layer and put the TouchPoints on that layer so that any scrolling of the layout doesn't interfere with tracking how much the player's finger has moved.

  • AllanR

    Thanks man u are our hero thats exactly what we wanted to do.

    perfect good work. probs


    Planlos Studios

  • So I just saw this and this looks helpful but wonder if you might have a better approach for what i'm looking to do.

    I am doing a simple "pong" style game and want two players to each have their half of the screen to touch and control. so of course this means they need to be able to touch freely independent of the other.

    my current system works well as long as only one player touches the screen at a time but i want to free that up and what i'm seeing is that when i touch the screen with one, the others touch doesn't register.

    i'm using a "while in touch", but i do have some other parameters like "it's lower than X or greater than X" so i made some effort to distinguish each other, but it's not enough.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would still do it just like in the example I did above...

    on any touch start, create a touchpoint object to track the touch

    while in touch update each touchpoint object

    on any touch end, destroy the related touchpoint object

    the only extra logic I would add is a lock on the paddles, to lock them to a touchpoint object, so that a player can't try to take over control of the other paddle. (remember to release the lock when the touch is released)

  • Awesome, yea i'll definitely give that a go. I'm in the middle of iOS certification hell but i see the light at the end of the tunnel.. once my head is wrapped around that and have a working pipeline i'm going to tackle this!

    Yea it will be interesting to see how it works. in my case the game has no paddle.. you run your finger in a swiping gesture to make a series of temporary barriers.. it was an old gamesalad game i made years ago and that game eventually just died / removed from store because it wasn't getting updated (i wasn't using gamesalad) so I wanted to revisit it with Construct.

  • Ok so I worked on my game with your touch stuff.. and it's "working" on a certain level but where mine varies from your example.. you have a single touch object.. i have two paddles that should be able to freely move on each side.

    You can see what happens in my example below. if you start touching on the left side.. and then press right side it is the left side reds.. if you touch on the right side then the left side spawns blues..

    here is what i have so far (test with touch device)

    the trouble i'm having is that i need to clearly distinguish two different paddles.. your example has a single "touchpoint" where I have two.

    once approach I haven't tried yet though might be to have a single "touchpoint" / "paddle" and based on the X coordinate determine perhaps a frame of animation to jump too.. still a few options but i'm trying to stick as close to your working example..

    I can't help but feel like i'm missing one small step in the whole thing to keep this from happening, but i'm in unfamiliar territory with multi touch and it's a bit tough to test quickly.. having to make exports and uploads to web site to really test.

  • well, that looked like fun, so I took a crack at it...

    you only add the Touch object to your project once, and that allows for multi-touch. So, you only need one TouchPoint sprite object to track each active touch.

    but you do need a way to tell which side the touch started on, so I also created a PlayArea sprite so that touches would know which player they belong to.

    each touch get assigned to the play area they are initially over, and that is used to select the correct energy bar, score instance, etc...

    the ball speeds up every time a player hits it. there are variable for how long the game goes for (5 right now), how many paddle instances a player gets before their energy runs out (30), how fast the paddles shrink, how much the ball speeds up, etc...

  • very cool! yea thought i could get away with not using a sprite on the screen and just based it on X or Y coordinates but this works well. Also yea I was in my more recent but ultimately unsuccessful attempt I was trying something similar with just one item because i could simulate a multitouch like this:

    not perfect but at least i could get unique IDs showing on multiple touches.. but things broke down when i tried my own logic there. Thanks for this solution! I've been kinda blocked on it all day.

    Nice to finally get a grasp of how the multi touch works in more ways than one.



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