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