How do I get the TouchID knowing the TouchIndex?

Get help using Construct 2

Post » Mon Mar 07, 2016 9:17 am

Hello!

I am working on mobile version of my game https://www.scirra.com/arcade/underground-jam/grounder-2-2331. And I would like to handle multi-touch on a mobile device since the core of the game is drawing solids in the scene.

I wanted to do something like this:
Image

However a I realized that there was no way to find the TouchID knowing the TouchIndex. I took a look at the Touch code and I realized that it was kind of simple by editing the Touch plugin:

runtime.js
Code: Select all
   Exps.prototype.TouchIDAt = function (ret, index)
   {
      index = Math.floor(index);
      
      if (index < 0 || index >= this.touches.length)
      {
         ret.set_float(0);
         return;
      }
      
      var touch = this.touches[index];
      ret.set_float(touch.id);
   };


edittime.js
Code: Select all
AddNumberParam("ID", "Zero-based index of the touch to get.");
AddExpression(31, ef_return_number, "", "Touch", "TouchIDAt", "Get the unique ID of a touch from a zero-based index of the touch.");


Please, anyone let me know if my "hack" was unnecessary. If not, maybe this should be a new feature @Ashley?

Thanks in advance!
B
231
S
6
G
9
Posts: 89
Reputation: 12,913

Post » Mon Mar 07, 2016 11:56 am

You shouldn't really use touch indices at all, they aren't a great idea. You should rely exclusively on touch IDs. The touch index is super confusing because if you release a touch with a lower index, the touch index changes. Touch IDs on the other hand never change.

Note event 20 in your picture is wrong: "Is touching" always tests every touch, so it is incorrect to assume that the corresponding touch is loopindex.
Scirra Founder
B
402
S
238
G
89
Posts: 24,628
Reputation: 196,023

Post » Tue Mar 08, 2016 5:57 am

Thanks @Ashley for you quick answer! :)

I agree with you about the "Is touching" event being incorrect. I tried to simplify the example of the issue but made more confusion. Please, let me show you the full set of event:

Image

... and a functional example of this events (if possible try it in a device that supports multi-touch):
https://dl.dropboxusercontent.com/u/109 ... index.html

My test cases:
    One touch drawing a line;
    Multiple touches starting together;
    A group A of touches starting together and then a group B of touches starting together, and group A and B ending together;
    A group A of touches starting together and then a group B of touches starting together, and then group A or B ending and the other group ending;

So, I wonder how could I do that without my hack and without an extra plugin? For example, if there is a way to iterate all current touches and get their TouchIDs.
B
231
S
6
G
9
Posts: 89
Reputation: 12,913


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests