Game Development Community

Detecting the 2nd Touch

by Joe Alanis · in iTorque 2D · 09/28/2009 (11:28 pm) · 4 replies

Hello, im working on moving some objects with multitouch, and so far i have been able to move them with the first touch, but the second object moves right behind the 1st object even when im only using one finger...

This is how it's supposed to work:
object "ch1" moves with the first touch
object "ch2" moves with the second touch...

im using this code:
function oniPhoneTouchMove(%touchCount, %touchX, %touchY)
{
	// Coordinate Transformations for iPhone screen
	%touchX -= 240;
	%touchX = 50*(%touchX/240);
	
	%touchY -= 160;
	%touchY = 37.5*(%touchY/160);
	
	if (%touchCount == 1)
		ch1.setPosition(%touchX, %touchY);
	
	if (%touchCount == 2)
		ch2.setPosition(%touchX, %touchY);

	x1.setvalue(%touchCount);

}
But why does the second object move also? (laggishly and akwardly... it suddenly jumps to the position of the touch...)

x1 is a GUI text field that allows me to see the result of %touchCount and it goes from 1 to 2 for fractions of a second even with only one finger touching the screen

I've enabled multitouch on the TGB Preferences and im sure my fingers are clean hahaha.

About the author

Director of the Animation and Digital Arts Bachelor @ ITESM Laguna Campus Twitter: @joealanis


#1
09/29/2009 (4:18 am)
Multitouch in iTorque2D doesn't work that well by default. Follow my guide here and read Justin's comments in the resource to get this properly implemented:

www.garagegames.com/community/resources/view/17225
#2
09/29/2009 (12:47 pm)
Dave, I don't really need multi-touch for my game, but currently my controls feels a bit clunky. I'm using onMouseDown and onMouseDrag to control a position of a spaceship.
Do you think that if I'll implement your multi-touch code, it may help?
#3
09/29/2009 (12:50 pm)
@Eyal Maybe but the only thing his resource added was the ability of different objects to receive mouse events without interfering with each other. This is important if they can move with one touch and then shoot with the other, without it they will interfere with each other.

I'd say get 1.3 but that breaks the onDrag functionality.
#4
09/29/2009 (1:03 pm)
My game is complete. gonna send it today to the appStore. I'm using 1.1 and it hasn't crashed in months so I'm afraid to change version. I'll try 1.3 when it's out an fixed.
Anyway thanks for the explanation on the multi-touch. You saved me a couple of hours ;)