DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Tracking/Identifying individual touches on iPhone

Tracking/Identifying individual touches on iPhone

David Amador user avatar by
David Amador
·
Apr. 20, 11 · Mobile Zone · News
Like (0)
Save
Tweet
1.58K Views

Join the DZone community and get the full member experience.

Join For Free

I got this question the other day, how to track individual touches if you are using a couple of fingers for a game?

Actually it’s pretty easy if you can access the touch previous position and it’s current position.

Let’s start with a small class to store the information

class Touch
{
public: Touch(); ~Touch();
 
      void update_position(float x, float y){ _current_position.x = x; _current_position.x = y; }
 
      bool is_same_touch(float x, float y)
     {
            if(_current_position.x == x && _current_position.y == y) return true; 
            return false;
      }
protected:
CGPoint _current_position;
};

Let’s a assume the “move” movement

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
        // Loop all touches
	for (UITouch *touch in touches)
	{		
                // Get current position in view
		CGPoint touchPoint = [touch locationInView:self];
                // Get previous position
		CGPoint prevPoint = [touch previousLocationInView:self];		
 
                // compare with your stored touch
                if(stored_touch->is_same_touch(prevPoint.x, prevPoint.y))
                {
                       // Do stuff with the movement
 
                       // Update
                       stored_touch->update_position(touchPoint.x,touchPoint.y);
                }
 
	}
}

As you can see you now have for each touch it’s current and previous position. So by storing each touch you can later compare it’s current position with the new touch old position.

IT

Published at DZone with permission of David Amador, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Is Cloud-Native Architecture?
  • Why Performance Projects Fail
  • Applying Kappa Architecture to Make Data Available Where It Matters
  • How To Deploy Apache Kafka With Kubernetes

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo