3 Replies - 533 Views - Last Post: 05 September 2012 - 02:43 PM

#1 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Tell when touch is released

Posted 30 August 2012 - 12:50 PM

Hey guys, I'm creating a small game that requires a swipe motion. I want to tell where the touch starts, and where it ends. So, my current solution would be to have a boolean, and in the onTouch() event, set the boolean to true, and if it were false before, record the position of that. So something like this:

if(touched == false)
{
    //Record position
    touched = true;
}



So I know how I would get the position when first touched. However, I would like to know how to record the position when the touch is released. And then record that position. I don't find an event that would allow me to do that. Does anyone have any suggestions? Help would be greatly appreciated. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Tell when touch is released

#2 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 276
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Tell when touch is released

Posted 30 August 2012 - 06:43 PM

In your onTouchListener:

public abstract boolean onTouch(View v, MotionEvent event)
{
    if(event.getAction () == MotionEvent.ACTION_UP)
	{
	 // the user has stopped touching the screen
	}
}

Was This Post Helpful? 1
  • +
  • -

#3 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: Tell when touch is released

Posted 30 August 2012 - 08:40 PM

Okay, thanks!
Was This Post Helpful? 0
  • +
  • -

#4 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: Tell when touch is released

Posted 05 September 2012 - 02:43 PM

Hey, so I was trying a different approach using your same basic concept, I thought it might be more convenient to the player if they it were based on any point of contact with the ball. Here's my code, it might explain better:

			if(event.getAction() == MotionEvent.ACTION_DOWN)
			{
				initTouchPoint.x = event.getRawX();
				initTouchPoint.y = event.getRawY();
				Touching = true;
			}
			
			
			else if(event.getAction() == MotionEvent.ACTION_MOVE)
			{
				upTouchPoint.x = event.getX();
				upTouchPoint.y = event.getY();
				//Debugging
				DebugText = (upTouchPoint.x - initTouchPoint.x) + "," + (upTouchPoint.y - initTouchPoint.y);
				Flick();
			}
			else if(event.getAction() == MotionEvent.ACTION_UP) Touching = false;



So as you can see, what I do is take the location of where the initial ACTION_DOWN is, and then I get the location every time the touch is dragged somewhere, but I show the what should be the difference between the upTouchPoint and the initTouchPoint coordinates, however, they always end up as 0,0 for some reason. I feel like I'm misunderstanding what ACTION_DOWN or ACTION_MOVE is.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1