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

  • SEARCH
  • Home
  • 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 8325559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:28:45+00:00 2026-06-09T00:28:45+00:00

I make my first app with cocos2d, so I am very new here my

  • 0

I make my first app with cocos2d, so I am very new here

my first problem:

I wont to make the object (boat) to follow my finger.

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [self convertTouchToNodeSpace: touch];
    NSLog(@"location X: %f", location.x);
    NSLog(@"location Y: %f", location.y);


    if(startGameButtonIsPressed == YES) {
        [boat runAction: [CCMoveTo actionWithDuration:1 position:location]];
    }
} 

It do follow but it is not fluid. If I move my finger quickly, it stops, and follow only if I stop.

The second Problem

How to calculate the distance between 2 points.

CGPoint currentLocation = ccp(boat.position.x, boat.position.y);    
float distanceApart = ccpDistance(currentLocation, location);

The problem, currentLocation is not constant on each point it has every time other value…. why?

Maybe becouse I have a scrolling background??

  • 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-09T00:28:47+00:00Added an answer on June 9, 2026 at 12:28 am

    You are calling [boat runAction: [CCMoveTo actionWithDuration:1 position:location]]; multiple times per second, which causes multiple CCMoveTo actions to be running simultaneously. This is not how cocos2d’s Action tools were designed to be used.

    If you want the boat to follow touches at a slower speed defined by you, you cannot queue up multiple CCMoveTo actions in response to ccTouchMoved:.

    Instead, push the UITouch objects (or NSValues of the CGPoints) onto an NSMutableArray. Then define a callback function to keep your boat moving after each CCMoveTo completes.

    Example Code:

    //...defined elsewhere, e.g. your header file:
        #define kBoatMoveTag 123
    
        NSMutableArray *touchQueue; //treat the array like a queue.
                                    //don't forget to alloc it before using.
    
    
    -(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
    {
        CGPoint location = [self convertTouchToNodeSpace: touch];
        NSLog(@"location X: %f", location.x);
        NSLog(@"location Y: %f", location.y);
    
        [touchQueue insertObject:[NSValue valueWithCGPoint:location] atIndex:0];
        [self continueBoatMovement];
    }
    
    -(void)continueBoatMovement {
        //if no queued point, or boat is already moving...
        if(touchQueue.count < 1 || [boat getActionByTag:kBoatMoveTag]) {
            return; //dont do anything 
        }
    
        NSValue valueOfPt = [touchQueue lastObject];
        [touchQueue removeLastObject];
        CGPoint newPt = [valueOfPt CGPointValue];
        float distance = ccpDistance(boat.position, newPt);
        float duration = distance / boatSpeed; //you must define boatSpeed somewhere
    
        CCMoveTo *move = [CCMoveTo actionWithDuration:duration position:newPt];
    
        CCSequence *moveSeq = [CCSequence actionOne:move two:[CCCallFunc actionWithTarget:self selector:@selector(continueBoatMovement)]];
        moveSeq.tag = kBoatMoveTag;
        [boat runAction:moveSeq];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make my first app for Microsoft Surface. I need to use
I am trying to make my first app using XNA, and I am having
I am a python programmer looking to make my first mobile app. I'd like
Im learning Rails by building apps. I want to make my first authenticated app:
I have a few labels on my first Ipad App. How to make them
How can I make an app play a video walkthrough (only) the first time
after first deploy with set :deploy_via, :copy for make changes in app now I'm
I'm trying make my first python app. I want make simple email sender form.
Newbie here programming my first app (having made several tutorial apps). I am using
So I have my first app ready, and when I try to make my

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.