Obtain velocity & direction through uipangesturerecognizer

Source: Internet
Author: User
In my code, it is used as follows:

Else if (recognizer. State = uigesturerecognizerstatechanged)
{

Cgpoint velocity = [recognizer velocityinview: recognizer. View];
Spriteact act = lastact;
// Nslog (@ "velocity x = % F, y = % F", velocity. X, velocity. y );
If (FABS (velocity. X)> FABS (velocity. y ))
{
// Left or righ
If (velocity. x> 0)
{
// Nslog (@ "gesture went left ");
Act = actleftdirection;
}
Else
{
// Nslog (@ "gesture went right ");
Act = actrightdirection;
}
}
Else if (FABS (velocity. X) <FABS (velocity. y ))
{
// Up or down.
If (velocity. Y> 0)
{
// Nslog (@ "gesture went up ");
Act = actupdirection;
}
Else
{
// Nslog (@ "gesture went down ");
Act = actdowndirection;
}
}
Else
{
# Ifdef dynamic_calc_direction
// Last act.
If (velocity. x * lastgesturevelocity. x + velocity. y * lastgesturevelocity. Y> 0)
{
// Nslog (@ "gesture went in the Same Direction ");
}
Else
{
// Nslog (@ "gesture went in the opposite direction ");
}
# Else
Act = lastact;
# Endif
}

For usage of several uigesturerecognizer types, refer to the following link:
Http://efreedom.com/Question/1-5187502/Can-Capture-Direction-Panned-Using-UIPanGestureRecognizer
Http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d
Http://ddesktop.googlecode.com/svn-history/r13/trunk/DDesktopClient/Classes/RemoteViewController.m

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.