How do I get the TouchID knowing the TouchIndex?

0 favourites
  • 3 posts
  • 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:

    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

    	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);
    	};[/code:1ihad1gs]
    
    edittime.js
    [code:1ihad1gs]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.");[/code:1ihad1gs]
    
    Please, anyone let me know if my "hack" was unnecessary. If not, maybe this should be a new feature 

    Ashley?[/p] [/p] Thanks in advance!

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Ashley for you quick answer! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    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:

    ... 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.

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