Game Development Community

[1.4.1] Touch callback doesn't work.

by Andrea Farid Marsili · in iTorque 2D · 02/23/2011 (12:59 pm) · 6 replies

I was working on a dragging and on a rotating behavior using the touch. Because I already manage to do it using the mouse I thought it would be simple but with touch callback my code doesn't work.
Initially I though that my code was wrong but after many try I decided to build up a new project with a simple function.
Here my simple code:
function dragClass::onLevelLoaded(%this, %scenegraph){
	$drag = %this;
	%this.setUseMouseEvents(true);
}

function dragClass::onMouseDown(%this, %modifier, %worldPosition, %clicks){
%this.setPosition(0, 0);
}

function dragClass::oniPhoneTouchDown(%touchCount, %touchX, %touchY){
	$drag.setPosition(0, 0);
}

The onMouseDown version work but the oniPhoneTouch version doesn't want to work. I tried also with other touch callback but the doesn't work. Any help?

#1
02/23/2011 (5:32 pm)
oniPhoneTouchDown is not a callback associated with any class or object. It is a stand alone function:

function oniPhoneTouchMove( %touchCount, %touchX, %touchY ) 
{
   // Put input reaction code here
}
#2
02/23/2011 (10:20 pm)
No one of the oniPhoneTouch function is a callback, they're all stand alone function. So I have to use mouse callback together with oniPhoneTouch function.

PS: we need a good reference about iTGB function, something like the TGB Reference.
#3
02/24/2011 (8:09 am)
No you don't have to use both.
decide which one to use if you use both you are wasting a lot of processing time.

generally you should have a little of either as possible (though with the oniphone ones its easier, cause they only exist once, if the function is there 2-3 times, then the last declared one will hold)
#4
02/24/2011 (11:52 am)
Understood but they don't want to work. The code is sooo simple.

function dragClass::onLevelLoaded(%this, %scenegraph){
	$drag = %this;
	%this.setUseMouseEvents(true);
}

function oniPhoneTouchDown(%touchCount, %touchX, %touchY){
	$drag.setPosition(0, 0);
}
The code doesn't work both with preview and simulator.
I tried to:
- delete the third line of code
- set a name for the actor
- use the function in game.cs
but cannot manage to detect touchDown.

Obviously the code work with onMouseDown but I already know how to work with TGB, I want to learn iTGB.
#5
02/24/2011 (12:12 pm)
If I recall, when I was developing my game I could not test in the simulator because the mouse functions would work but the touch functions would ONLY work with the actual device.

I could be wrong but if I remember correctly that is what happened so I never used the simulator. I only tested on my iPod Touch.
#6
02/24/2011 (1:15 pm)
The code doesn't work both in the simulator and in the device.
I also tried to build the Shooter project example to play it on my iPod and the joystick's dragging system (together with the movement system) doesn't work.