Subscribe ( )

iPhone Programming Tutorials


 

Forum

You must be logged in to post Login Register

Search 

Tap vs. Swipe Events

User Post

10:43 pm
March 13, 2009


meekismurder

Noob

posts 2

1

Hello everyone-

I am developing my first iPhone game. The tutorials on icodeblog have been very helpful, but I'm having a bit of trouble with a certain element of the input control. The touch controls of the game require being able to distinguish between when the user drags his finger or when the user simply taps (or holds) and lifts up. A comparison would be the way EA Tetris for iPhone handles moving and rotating the tetriminos (a tap rotates it, a swipe/drag moves it).

I have accomplished dragging with the following code (this is just for dragging to the right):

//Right Side Swipe

if (touchLocation.x > lastTouchPos.x) {

//If gesture is greater than move distance

if (touchLocation.xlastTouchPos.x > MOVE_SPEED) {

CGPoint newLocation = CGPointMake(myObject.center.x + MOVE_SPEED,myObject.center.y);

if (newLocation.x <= BOUNDS_RIGHT) {

myObject.center = newLocation;

}

lastTouchPos.x += MOVE_SPEED;

}

}

The trouble is, I'm not sure how to check for a tap, since if I do the comparison:

if (touchLocation.x = lastTouchPos.x) {…}

This seems to interpret swipe gestures as well. What I really need is a way to see if the user lifts his finger at the same position he puts it down. I don't think the solution would be using an NSTimer because it doesn't matter how short or long they tap, just as long as they didn't drag their finger. Anyone know a good way to do this?


2:51 pm
March 19, 2009


meekismurder

Noob

posts 2

2

Thanks for nothing! Smile

Well anyway, I figured it out myself, in case anyone was curious, I accomplished it by just asking touchesEnded if the tapCount was equal to 1. Duh. 

Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

3 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 934 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.