Game Development Community

(Solved) Iphone touched command isDown help?

by Eliezer Cardona · in iTorque 2D · 06/11/2011 (8:50 am) · 21 replies

Hi I have created a image to be a button and in script I called it Button. I have created a player and in script i called it player. When i was looking in the document dragging, which I do not use this one. I looked in the code for music player and i saw isDown. I try doing some coding to making the player move up. I have success but when it come to play on keyboard I am fine. Can you guys share some expertise, did I do something wrong with the coding?

If you know more commands for the touch and where did you find it can you share it thanks. Also I have the documents for what came with Itorque which I take a look. If you know the section also so you can tell me where to look.

function oniPhoneTouchUp( %touchCount, %touchX, %touchY ) 
{
   Button.isDown = false;
}

function oniPhoneTouchMove( %touchCount, %touchX, %touchY ) 
{
   if(Button.isDown)
   {
      %this.player.setLinearVelocityY(-55);
   }
   else
   {
      %this.Button.setLinearVelocityY(-55);
   }
}
function Cloud::onMouseDown(%this, %modifier, %worldPos)
{
   if(Button.isDown)
   {
      return;
   }
   else
   {
      Button.isDown = true;
   }
}

Thanks for looking
Page «Previous 1 2
#1
06/11/2011 (11:38 am)
A few things wrong with your code.

1. You are referencing %this.player in a function where there is no %this parameter

2. Next, I'm not sure what you are doing with the Cloud, Button and player. Is Cloud the button? Are you sure you don't mean Button::onMouseDown?

3. On one line, you set the player's linear velocity. In other other case, you set the button.

Here is how my code would look:

function oniPhoneTouchUp( %touchCount, %touchX, %touchY ) 
{
   Button.isDown = false;
}

function oniPhoneTouchMove( %touchCount, %touchX, %touchY ) 
{
   if(Button.isDown)
   {
      player.setLinearVelocityY(-55);
   }
   else
   {
      player.setLinearVelocityY(55);
   }
}

function Button::onMouseDown(%this, %modifier, %worldPos)
{
   if(Button.isDown)
   {
      return;
   }
   else
   {
      Button.isDown = true;
   }
}

Also, make sure you have useMouseEvents set to true for the Button. Otherwise, onMouseDown will not work. Additionally, Multitouch needs to be enabled for the oniPhoneTouchXXX functions to work.
#2
06/11/2011 (12:11 pm)
Thank you Michael Perry. I see where I might have messed up. I put the else to the button to move the button if it hit else if. So I Can atleast know if one of my statement would actually work. I am not home right now to try the code would like to get back at you in case something not working correct.

Thank you for the posting
#3
06/11/2011 (1:55 pm)
Happy to help. Just let me know if it all works.
#4
06/11/2011 (8:49 pm)
Hi Michael I ran it and tested it and working perfect. I cant believe I did a little stupid thing should of realized it from testing and tutorials. I have to pay close attention to small stuff. Thank you so much and it working as I wanted it. Now I can keep moving forward. I have to say as this being my first engine buying and learning as I go into more programing and other stuff I love this. I appreciate your contribution and others as well. :)
I am a happy customer and for Garagegames I think it the best. Thumbs up !!!
#5
06/11/2011 (10:06 pm)
Great. I'm glad it's working and that you are enjoying working with the engine as much as I do. Keep up the progress and we'll be around if you have more questions =)
#6
06/13/2011 (12:37 pm)
Hi Michael thanks for the help before. I came into another problem With the same code but notice something now after practicing for a while. I put to play an animation and when i clicked on the button it would play but when I let go of the button it would still be playing the animation. Is there a break code that I can use as a mouse release or touch release.
if(Button.isDown)
   {
    
     player.playAnimation(stan);
   }
   else
   {
      player.playAnimation(walking);
   }
#7
06/13/2011 (12:43 pm)
There are two. oniPhoneTouchUp or sceneWindow2D::onMouseUp should work is the right flags are set. Multitouch must be enabled for oniPhoneTouchUp to work. Use Mouse Events must be enabled on the sceneWindow2D object for onMouseUp to trigger.
#8
06/13/2011 (1:16 pm)
HI Michael i see from the other tutorial but this part is a bit confusing to me. I have already set up the multitouch but not sure how to set up the code. When run the code it would play the game. But when I touch the button it would play the running animation and when I stop touching it it would continue to play the running animation.
function oniPhoneTouchUp( %touchCount, %touchX, %touchY ) 
{
   Button.isDown = false;
}

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

}

//Luma: Tap support
function oniPhoneTouchTap (%this, %modifier, %pos, %clickCount )
{ 
 if(Button.isDown)
	return;
    else
    {
	Button.isDown = true;
    }
}
function Button::onMouseUp(%this, %modifier, %pos, %clickCount)
{
   if(Button.isDown)
   {
     player.playAnimation(walking);
   }
   else
   {
	
      player.playAnimation(stan);
}
}
#9
06/14/2011 (7:36 am)
Anyone can help with this little problem keep trying but for some reason it would not work. I try different ways but if I press the button it change back and forth any leads would be appreciated.
#10
06/14/2011 (7:42 am)
You don't appear to be changing the animation in the oniPhoneTouchUp function. I can see it being played in onMouseUp. Move the code from that function into the iPhone touch up function to see what happens.
#11
06/14/2011 (8:09 am)
Hi Michael thanks for the reply I did what you told me but when I do that it would not change execute the else statetment for standing. What it would do is when i play the game and press the screen it would go into running animation but never execute the standing after done.
#12
06/14/2011 (8:50 am)
Can you post your full code for all the touch commands, in its current state?
#13
06/14/2011 (8:51 am)
Also, could you paste the contents of your console.log into Pastebin? Just post the link to it so I can look for any errors.
#14
06/14/2011 (9:27 am)
Hi Michael here is my code I try doing and thank you. I don't have to much code maybe I am missing alot but here is what I got. Here it is http://pastebin.com/UXKu922q

#15
06/14/2011 (9:36 am)
Do you want him to play the walk animation when touching, then play the stand animation when you are not touching?
#16
06/14/2011 (9:44 am)
Yes that is correct that is what I want to do. Thank you for looking at it been struggling on this one.
#17
06/14/2011 (9:57 am)
Alright, so there are a couple of problems here.

1. You had the animations swapped
2. You were doing too many if/else checks, which were short circuiting

I have simplified your code, which should make this work as long as there are no syntax errors, the animations exist and Button is an existing object that uses mouse events:

function oniPhoneTouchDown( %touchCount, %touchX, %touchY ) 
{
   // If you are using a specific sprite for touch
   // you do not need this. Use the ::onMouseDown
}

function oniPhoneTouchUp( %touchCount, %touchX, %touchY ) 
{
   if(Button.isDown)
   {     
     player.playAnimation(standing);
     Button.isDown = false;
   }
}

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

}

//Luma: Tap support
function oniPhoneTouchTap (%this, %modifier, %pos, %clickCount )
{
   // No need to use this for your code
}

// This callback is invoked when the Button is touched or clicked
function Button::onMouseDown(%this, %modifier, %pos,%clickCount)
{
   if(!Button.isDown)
   {
      Button.isDown = true;
      player.playAnimation(walking);
   }
}
function Button::onMouseUp(%this, %modifier, %pos, %clickCount)
{
   // This function is not needed if you are using oniPhoneTouchUp
}

Make sure you read the comments to see why I removed code from certain functions. It should be noted that there are two different ways to check to see if a sprite is being touched. One way is shown above, where you use Button::onMouseDown.

The other completely avoids this function, just using oniPhoneTouchDown. This method is shown in the Pong Tutorial I posted.

For the sake of simplicity, just stick with the method shown in the code I posted here.
#18
06/14/2011 (10:26 am)
Thank you Michael you are the best. I did try using the !Button with another parameter but not like yours. I understand more on how it works. I just need to think more as a mad scientist so it can be as good as yours lol.

I want to get your opinion on something. I was thinking of buying TGB Platformer Kit. Since I own IT2D will it work with this since it a reference to T2D just made for Iphone version. I want to enhance my skills on making games and add features to it.
#19
06/14/2011 (10:36 am)
Quote:I was thinking of buying TGB Platformer Kit. Since I own IT2D will it work with this since it a reference to T2D just made for Iphone version.
The Platformer Kit is not iOS ready out of the box. People who want the iOS port usually contact the creator, Phillip O'Shea. He manually transmits the work he put into making it run on iTorque 2D. I have not reviewed the code, so I cannot speak on the difficulty to implement in the latest version of iT2D.

If you are completely new to T2D, iT2D and the Platformer Kit, it can be really beneficial or a roadblock just to get it to work. Perhaps others who have used it can chime in. I will see if I can drag someone in.
#20
06/14/2011 (11:05 am)
Ok thank you very much on the information Michael and everything you have done. This made my week, very glad you help on this thread. It would be great if any one used that TGB Platformer kit can tell me reviews such as pros and cons. I have downloaded the Pong tutorial and will be keeping close eyes on it and also I found a video of the live ping pong tutorial I will take a look into that as well.
Page «Previous 1 2