Game Development Community

Blatantly Wrong (solved)

by rennie moffat · in iTorque 2D · 03/25/2011 (10:17 am) · 12 replies

Ok, this is my last post for a while on this, but I have been reading the docs but I am not getting my iPhone commands to work.




Example, this behavior....
if (!isObject(gesturesBehavior))
{
   %template = new BehaviorTemplate(gesturesBehavior);
   
   %template.friendlyName = "gesturesBehavior";
   %template.behaviorType = "gesturesBehavior";
   %template.description = "gesturesBehavior";
   
   %template.addBehaviorField(centerOnMouse, "Center the object on the mouse", bool, false);
   %template.addBehaviorField(toggleDragState, "Start dragging on one click, stop dragging on the next click", bool, false);
}

function gesturesBehavior::onBehaviorAdd(%this)
{
	%this.owner.setUseMouseEvents(true);
}


// This callback is invoked when the cloud is touched or clicked
function gesturesBehavior::onMouseDown(%this, %modifier, %worldPos)
{
	echo("onMouse Down::::::::::");
	echo("onMouse Down:::::");
	echo("onMouse Down::::");
	echo("onMouse Down:::");
	echo("onMouse Down::");
	$cloud.dragging = true;
   
}

function gesturesBehavior::onMouseUp(%this, %modifier, %worldPos)
{
   	echo("onMouse Up:::");
	echo("onMouse Up:::::");
	echo("onMouse Up::::::");
	echo("onMouse Up::::::::");
	echo("onMouse Up:::::::::::");
	$cloud.dragging = false;
}

function gesturesBehavior::oniPhoneTouchDown( %touchCount, %touchX, %touchY ) 
{
	echo("iPhone Touch Down");
	echo("iPhone Touch Down");
	echo("iPhone Touch Down");
	echo("iPhone Touch Down");
	echo("iPhone Touch Down");
	echo("iPhone Touch Down");
	echo("iPhone Touch Down");
	echo("iPhone Touch Down");
	
}

function gesturesBehavior::oniPhoneTouchUp( %touchCount, %touchX, %touchY ) 
{
	echo("iPhone Touch Up");
	echo("iPhone Touch Up");
	echo("iPhone Touch Up");
	echo("iPhone Touch Up");
	echo("iPhone Touch Up");
	echo("iPhone Touch Up");
	echo("iPhone Touch Up");
	echo("iPhone Touch Up");
}

function gesturesBehavior::oniPhoneTouchMove( %touchCount, %touchX, %touchY ) 
{
	echo("iPhone Touch Move");
	echo("iPhone Touch Move");
	echo("iPhone Touch Move");
	echo("iPhone Touch Move");
	echo("iPhone Touch Move");
	echo("iPhone Touch Move");
	echo("iPhone Touch Move");
	echo("iPhone Touch Move");


   	echo("%this.owner.position" @ %this.owner.position);
     // Get X value from the %touchX variable
    %xPosition = getWord(%touchX, 0);
      
    // Get Y value from the %touchY variable
    %yPosition = getWord(%touchY, 0);
      
    // Convert the touchscreen coordinates to world coordinates
    %worldPoint = sceneWindow2D.getWorldPoint(%xPosition, %yPosition);
      
    // Now that we have world coordinates, set the cloud to that position
    %this.owner.setPosition(%worldPoint);
    %this.owner.setDamping(10);
      
    echo("on iPhone Move");
    echo("%worldPoint" @ %worldPoint);
   
}




I removed the if dragging condition like in the docs, however, I still get no echo return from any of the iPhone Gesture commands. Odd I am sure. I also popped them into the game.cs and I receive no echo commands when running on the simulator. If I am doing something blatantly wrong, please pass along your knowledge.








About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
03/25/2011 (10:18 am)
Did you enable the multi-touch flag in the editor?
#2
03/25/2011 (10:29 am)
Yes I did.




I recompiled everything. Cleaned, a few times, tested on both simulator and device but no dice.

:/
#3
03/25/2011 (10:35 am)
Is there a reason you rewrote the code for the oniPhoneXXX functions?

Quote:
If you look through the rest of game.cs, you will see there are iPhone specific touch functions already written. They exist, but are blank:

// Called when the user touches the screen in any way
// %touchCount - How many fingers are touching
// %touchX - Screen coordinate of the touch on the X axis
// %touchY - Screen coordinate of the touch on the Y axis
function oniPhoneTouchDown( %touchCount, %touchX, %touchY )
{
}

// As soon as the user stops touching the screen
// %touchCount - How many fingers were removed from the screen
// %touchX - Where the finger left the screen on the X axis
// %touchY - Where the finger left the screen on the Y axis
function oniPhoneTouchUp( %touchCount, %touchX, %touchY )
{
}

// Called continuously when a user has touched the screen, then started dragging
// %touchCount - How many fingers are currently moving across the screen
// %touchX - Screen coordinate of the dragging on the X axis
// %touchY - Screen coordinate of the dragging on the Y axis
function oniPhoneTouchMove( %touchCount, %touchX, %touchY )
{
}

// Called when the user quickly taps the screen
// %touchCount - How many fingers tapped the screen
// %touchX - Screen coordinate of the tap on the X axis
// %touchY - Screen coordinate of the tap on the Y axis
function oniPhoneTouchTap ( %touchCount, %touchX, %touchY )
{
}


Unlike onMouseDown, the above functions do not inherently know what object is being touched. They just provide coordinates.

They are stand alone functions. They are not a part of any object. They are not member functions. They exist on their own, so you cannot do function gesturesBehavior::oniPhoneTouchUp.
#4
03/25/2011 (10:38 am)
Oh ok well two things.
A. I thought I had asked that and said it did not matter. I did it thinking, that it might be easier for the engine to work if specific objects, blah blah blah... I get you.
B. I have it running in my game.cs as well tho and with echo calls, those calls are not being shown.



:?


game.cs...
function oniPhoneTouchDown( %touchCount, %touchX, %touchY ) 
{
	echo("in game .cs");
	echo("on iphone touch down");
	echo("in game .cs");
	echo("on iphone touch down");
	echo("in game .cs");
	echo("on iphone touch down");
}

function oniPhoneTouchUp( %touchCount, %touchX, %touchY ) 
{
	echo("in game .cs");
	echo("on iphone touch up");
	echo("in game .cs");
	echo("on iphone touch up");
	echo("in game .cs");
	echo("on iphone touch up");
}

function oniPhoneTouchMove( %touchCount, %touchX, %touchY ) 
{
	if($cloud.dragging == true)
	{
	echo("in game .cs");
	echo("on iphone touch move");
	echo("in game .cs");
	echo("on iphone touch move");
	echo("in game .cs");
	echo("on iphone touch move");
		
		
		echo("%this.owner.position" @ %this.owner.position);
        // Get X value from the %touchX variable
        %xPosition = getWord(%touchX, 0);
      
        // Get Y value from the %touchY variable
        %yPosition = getWord(%touchY, 0);
      
        // Convert the touchscreen coordinates to world coordinates
        %worldPoint = sceneWindow2D.getWorldPoint(%xPosition, %yPosition);
      
        // Now that we have world coordinates, set the cloud to that position
        %this.owner.setPosition(%worldPoint);
        %this.owner.setDamping(10);
      
        echo("on iPhone Move");
        echo("%worldPoint" @ %worldPoint);
	}

}
#5
03/25/2011 (10:45 am)
Do me a favor and look at your projectFiles/common/commonConfig.xml file. Do you see the following:

<iFeatureUseMultitouch>1</iFeatureUseMultitouch>
#6
03/25/2011 (10:48 am)
Another quick question, and forgive me if this seems basic, but how are you checking to see if they are not being called?
#7
03/25/2011 (10:48 am)
Yes,
It was set to "0". Odd, as in the editor I had set it to on ("multiTouch Support").

Anyhow, that did cheers Michael, sorry for raising any unnecessary flags I sure you are pulling your hair out enough already.
#8
03/25/2011 (10:49 am)
Re, quest 2.

How to see if they are NOT being called?


Um, well I am simply using echoes. If I never see the echo returned I assume it is not being called.


:
#9
03/25/2011 (10:54 am)
K. Glad it's resolved
#10
03/25/2011 (10:56 am)
Thanks.








My answer for question was correct right?
#11
03/25/2011 (11:12 am)
Yup. You're right. Just wanted to make sure you were looking for the echos while debugging on a device and not on a desktop. Looks like you are good to go.
#12
03/25/2011 (11:16 am)
Swweeeet.

chanks bud!