Game Development Community

multitouch madness

by Henry Shilling · in iTorque 2D · 07/26/2010 (3:27 am) · 15 replies

In the file scripts/game.cs we have 3 functions:

function oniPhoneTouchDown( %touchCount, %touchX, %touchY )

function oniPhoneTouchUp( %touchCount, %touchX, %touchY )

function oniPhoneTouchMove( %touchCount, %touchX, %touchY )

What do they do and how do they work? From what I see they are kind of insane.

Touch the screen and TouchDown will read %touchCount = 1 %touchX, %touchY both give what you would expect. Now touch the screen again without lifting the previous touch: %touchCount = 1, do it with 5 fingers, each touch reads 1, the only way to get more than one is to touch with multiple fingers simultaneously.

Similarly Touch move works like this: touch with 1 finger then another. Move either finger, whichever finger moves first gets move 1. TouchUp is also exctly the same.

Why is this madness? I would expect that when I touch it gives me touch 1 (or 0) the next touch would of course be touch 2 etc. When I move say the second finger it would report TouchMove as 2 and when I lifted a finger it would report as lift 2 etc. Am I wrong? How else can we keep track of what touch is what?



#1
07/26/2010 (3:38 am)
Regarding Touch1, then Touch2, then TouchMove1 potentially being the finger attached to Touch2, if I read you right, is that Touch and TouchMove are completely separate events and in a way, are no way related.



So in that sense it makes sense that Touch1 has the potential to be Touch1 or 2!


I do have a few questions on this tho...
I just began testing my game. It is not yet optimal in performance so, that could easily be the answer for me, BUT is there any difference between onIPhoneTouchUp() and onMouseUp(). I mean I presume they are identical in purpose but in terms of effectiveness is what I am wondering. Is onIPhoneTouchUp() preferable to use?
#2
07/26/2010 (4:20 am)
Well I found this resource: http://www.torquepowered.com/community/resources/view/19809 It makes the touch work like I expected it to.

I don't know if using Touch up over mouse up is preferred. I dont know if onIPhoneTouchUp can be used a s a callback either.
#3
07/26/2010 (6:47 am)
Rennie, onMouseUp() only works on the desktop, and onIPhoneTouchUp() only works on the actual device (or the device simulator). At least that is case in version 1.3.1, although it might be different in version 1.4. They serve the same purpose though.
#4
07/26/2010 (12:52 pm)
not really Mark.
Cause onMouse can only respond to one / the first touch.
While oniPhoneTouch serves up to 8 (or should) depending on the device


An additional major difference is that the mouse callbacks are restricted and fully bound to objects that are enabled to handle mouse input.

the iphone input callbacks on the otherside are always there and in relation to the screen without any binding to a specific object or the requirement that any object can receive mouse events.


Also its possible ot use the mouse events on the iphone (without the hackery. From my experience its just a matter of fixing the gui to be really fullscreen, enabling the window2d object to receive the events and have all iphone input functions at least defined. Thats at least the combination I had when I got the mouse callbacks working again), but you can't use the iphone events anywhere outside the simulator and device.
#5
07/26/2010 (4:59 pm)
Marc is spot on with his assessment of how onMouseXXX versus oniPhoneTouchXXX works. Simply having the empty iPhone input functions defined gets you the results one would expect were you using a mouse.

@ Henry - Have you actually implemented Edward's Multi-Touch enhancement against 1.4? That resource was going to be my next move after getting the Universal build portion working.
#6
07/26/2010 (5:47 pm)
@Brian Yes I did and it works great so far. Pretty easy too, drag, drop, compile.

I am not doing a universal build of my game as I think it would really be too small on the phone. I am converting one of my xbox games. 1024x768 is close enough to 1280x720 to make it pretty cool.

It really seems more than logical that you could track each touch.
#7
07/26/2010 (5:54 pm)
@ Henry - Thanks for the feedback. It's good to know this resource is still applicable as multi-touch is a core feature of the iDevices--something that sets them apart from other platforms and allows for unique implementations of features which would, otherwise be impossible. For example, in your XBox game port, you could easily emulate the actions of the a, b, x, y, l-trigger, r-trigger, etc. buttons of a typical XBox controller by assigning those to specific multi-touch actions (I won't even go into how cool actual gesture recognition could be). This is undoubtedly what you are doing and I think that is a fantastic way to expand the audience base or your game. Nice plan!
#8
07/26/2010 (6:42 pm)
The thing I needed most was two joystick type inputs, I have changed it around a bit and now it's even cooler. I think I can make an input like Geometry wars for the iPad.

I tried Deans really cool gamepad, and it worked well with one pad. Two pads and it messed up. He may have fixed it since I should really take a look. Last time I messed with it was beta and it seemed whenever I recompiled the source iTGB blew up. I am not yet ready to deal with that again.

http://www.torquepowered.com/community/resources/view/19691

#9
07/27/2010 (4:21 am)
Yeah, sorry about that. I was getting it confused with onMouseDragged(). I have a number of objects that respond to mouse events, and I didn't have to do anything special to make those work, so the other mouse events must obviously work correctly.
#10
07/30/2010 (3:30 am)
function oniPhoneTouchDown( %touchCount, %touchX, %touchY )

function oniPhoneTouchUp( %touchCount, %touchX, %touchY )

function oniPhoneTouchMove( %touchCount, %touchX, %touchY )

Why these functions can not work?

My OS is Windows!
#11
07/30/2010 (3:44 am)
huyan, those are iPhone specific functions so they will only work when you run your program on the iPhone simulator on or the actual iPhone device. To do that you need to use XCode on the Mac. Since you mentioned that you are using Windows, I'm guessing that are currently running your code on the desktop via the iTGB editor, right? If that is the case, only the mouse events functions will work, such as onMouseUp() etc.
#12
07/30/2010 (4:17 am)
Mark Davles! Thank you for your help? Can OnMouseUp work on the iPhone simulator?
#13
07/30/2010 (4:35 am)
Yes, all of the mouse functions (except onMouseDragged) will work on the iPhone simulator, and on the desktop also. If you only need to do single touches, I'd recomment using onMouseUp() and onMouseDown() etc, and don't worry about the oniPhoneTouchUp/oniPhoneTouchDown. Your program will then run the same on all platforms, including Windows. That's what I do in my game.
#14
07/30/2010 (6:54 am)
OK, It is Great! Thanks a lot! I am a Chinese, My English is very poor, but I understand what you say! Thank you!!!!!
#15
07/30/2010 (7:34 am)
No problem, if you have more questions feel free to post them. I can tell that your first language is not English, but I understand what you say also.