Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:52:46+00:00 2026-06-17T12:52:46+00:00

I am trying to implement game control that will be changes direction of unit

  • 0

I am trying to implement game control that will be changes direction of unit
movement. So if i do right swipe it turns to the right, if i do down swipe it turns to the down direction etc.

It’s cocos2d game, and i’am using CCNode+SFGestureRecognizers with UISwipeGestureRecognizer.

At now I have next implementation for it

UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
        [self addGestureRecognizer:rightSwipeGestureRecognizer];
        rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
        rightSwipeGestureRecognizer.delegate = self;
        [rightSwipeGestureRecognizer release];
        
        UISwipeGestureRecognizer *upSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleUpSwipe:)];
        [self addGestureRecognizer:upSwipeGestureRecognizer];
        upSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
        upSwipeGestureRecognizer.delegate = self;
        [upSwipeGestureRecognizer release];
        
        UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
        [self addGestureRecognizer:leftSwipeGestureRecognizer];
        leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
        leftSwipeGestureRecognizer.delegate = self;
        [leftSwipeGestureRecognizer release];
        
        UISwipeGestureRecognizer *downSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleDownSwipe:)];
        [self addGestureRecognizer:downSwipeGestureRecognizer];
        downSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
        downSwipeGestureRecognizer.delegate = self;
        [downSwipeGestureRecognizer release];

but the problem is that for to recognize the following gesture you need to lift your finger from the screen. if you do not lift a finger after the first swipe, it will recognize only the first swipe.

at now:

enter image description here

How it should be:

enter image description here

What the best way to do that? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:52:48+00:00Added an answer on June 17, 2026 at 12:52 pm

    Ok, there is my solution. I dont think that is really good solution, but in my case it works, because i need getting direction at every time interval.

    So, in my CCLayer subclass:

    #define SWIPE_LENGTH        60
    #define SWIPE_TANGENT       2
    
    ...
    
    @property(nonatomic, assign) CGPoint latestLocation;
    
    ...
    
    -(id) init
    {
        if( (self=[super init]) )
            {
                self.isTouchEnabled = YES;
            }
        return self;
    }
    
    - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        CGPoint location = [touch locationInView:[touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];
        self.latestLocation = location;
    }
    
    - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        CGPoint location = [touch locationInView:[touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];
        CGPoint delataLocation = CGPointMake(location.x - self.latestLocation.x, location.y - self.latestLocation.y);
        if ( sqrt(pow((delataLocation.x), 2) + pow((delataLocation.y), 2) ) > SWIPE_LENGTH ) {
            if (delataLocation.y > 0 && delataLocation.y > SWIPE_TANGENT * ABS(delataLocation.x))
            {
                [self handleSwipeWithDirestion:SDirectionTypeUp];
            } else if (delataLocation.y < 0 && ABS(delataLocation.y) > SWIPE_TANGENT * ABS(delataLocation.x))
            {
                [self handleSwipeWithDirestion:SDirectionTypeDown];
            } else if (delataLocation.x > 0 && delataLocation.x > SWIPE_TANGENT * ABS(delataLocation.y))
            {
                [self handleSwipeWithDirestion:SDirectionTypeRight];
            } else if (delataLocation.x < 0 && ABS(delataLocation.x) > SWIPE_TANGENT * ABS(delataLocation.y))
            {
                [self handleSwipeWithDirestion:SDirectionTypeLeft];
            }
            self.latestLocation = location;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement something similar to the flight control game. There will
Right, I'm trying to implement this game, http://www.helicoptergame.net/ , but I'm struggling with the
I'm trying to implement invitations with Game Center and there's one thing that i
I'm trying to implement a game loop that limits the velocity of execution of
I'm trying to implement a fairly simple card game in Python so that two
I was trying to implement the Sorry! board game using C++ such that 4
I'm currently trying to implement a card game called 500. Right here, I'm trying
I am trying to implement background music into an Android game that I am
Trying to implement a timer for my game that I'm making. I have a
Im trying to implement a keyboard class in my game that has two modes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.