Game Development Community

[solved] I need help on using onTouchUp for more than one time

by Ghonium · in iTorque 2D · 01/06/2012 (12:14 pm) · 2 replies

hello guys
I have a code
I use it and it work fine during the level
but I dont know why I cant use it more than one time in the current level

the code simple do
is on touch up, it should start using the item
and remove one item from the list, this done perfect

but when I touch it again nothing happens, I want to use more than one time on the same level
anyone know whats wrong with this plz ?

function speedButton::onTouchUp(%this, %touchID, %worldPos)
{
   echo("Finger " @ %touchID @ " untouched the thing at " @ %worldPos);

   // If the finger being lifted is the same as the one assigned
   // at the first touch event, wipe the touch ID
      if(speedButton.touchID $= "")
      {      speedButton.touchID = %touchID;

       //On touch speed button
       if($item[1] > 0) //if i have  power
         {
         //remove 1 power from item
         $item[1] -= 1;
    	 speedQuantityGui.setValue($item[1]);
    	 SaveItems();
    	 speedButton.Visible = 0;
    	 schedule(3000, 0, "ShowSpeed"); 

         }
        
       }

}

function ShowSpeed()
{
	    	 speedButton.Visible = 1;

	}

#1
01/06/2012 (8:42 pm)
Hey Ghonium,

This code checks to see if you have a touch ID already assigned to your 'speedButton'
if(speedButton.touchID $= "")
      {    
  speedButton.touchID = %touchID; //assigned touchID here
If you don't have an id (say , from your onTouchDown function) then it assigns the id 'finger1' say... then executes your code.

The next time it executes your code, it looks to see if the touch is null ("") , it isn't anymore, because we assigned it a touchID ., and so skips your code from now on.

If you aren't using the touch down, You could take the that whole if statement, (and it' braces {} ) out.



#2
01/08/2012 (7:41 am)
thank you very much :)
it work perfect now :)