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 735657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:30:55+00:00 2026-05-14T07:30:55+00:00

I’m developing a line drawing game, similar to Flight Control, Harbor Master, and others

  • 0

I’m developing a line drawing game, similar to Flight Control, Harbor Master, and others in the appstore, using Cocos2D.

For this game, I need a CCSprite to follow a line that the user has drawn. I’m storing a sequence of CGPoint structs in an NSArray, based on the points I get in the touchesBegin and touchesMoved messages. I now have the problem of how to make my sprite follow them.

I have a tick method, that is called at the framerate speed. In that tick method, based on the speed and current position of the sprite, I need to calculate its next position. Is there any standard way to achieve this?

My current approach is calculate the line between the last “reference point” and the next one, and calculate the next point in that line. The problem I have is when the sprite “turns” (moves from one segment of the line to another).

Any hint will be greatly appreciated.

  • 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-05-14T07:30:56+00:00Added an answer on May 14, 2026 at 7:30 am

    Why do you code your own tick method? Why don’t you just use the built-in CCMoveTo method?

    (void) gotoNextWayPoint {
        // You would need to code these functions:
        CGPoint point1 = [self popCurrentWayPoint];
        CGPoint point2 = [self getCurrentWayPoint];
    
        // Calculate distance from last way point to next way point
        CGFloat dx = point2.x - point1.x;
        CGFloat dy = point2.y - point1.y;
        float distance = sqrt( dx*dx + dy*dy );
    
        // Calculate angle of segment
        float angle = atan2(dy, dx);
    
        // Rotate sprite to angle of next segment
        // You could also do this as part of the sequence (or CCSpawn actually) below
        // gradually as it approaches the next way point, but you would need the
        // angle of the line between the next and next next way point
        [mySprite setRotation: angle];
    
        CCTime segmentDuration = distance/speed;
    
        // Animate this segment, and afterward, call this function again
        CCAction *myAction = [CCSequence actions: 
              [CCMoveTo actionWithDuration: segmentDuration position: nextWayPoint], 
              [CCCallFunc actionWithTarget: self selector: @selector(gotoNextWayPoint)],
              nil];
    
        [mySprite runAction: myAction];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.