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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:21:14+00:00 2026-05-28T14:21:14+00:00

In my app, I need to draw a path where every coupe of frames,

  • 0

In my app, I need to draw a path where every coupe of frames, an additional point is added to the end of it.

I could implement this in the following way:

- (void) draw
{
  glEnable(GL_LINE_SMOOTH);
  glColor4f(0.0,0.0,1.0,1.0);

  BOOL first = YES;
  CGPoint prevPoint;

  for (NSValue* v in points)
  {
    CGPoint p = [v CGPointValue];

    if (first == YES)
      first = NO;
    else
      ccDrawLine(prevPoint, p);

      prevPoint = p;
  }
}

But I’m afraid this will not scale well as the path could (and almost always would) get pretty long.
Is there a better more “economical” way to implement this?

  • 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-28T14:21:15+00:00Added an answer on May 28, 2026 at 2:21 pm

    Look at the standard cocos2d RenderTextureTest sample code which includes a fingerpainting class. A simplified version of the main method that does the drawing is shown below. You could take this logic and use it to just render the path under your control rather than driven by the touch events.

    -(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        CGPoint start = [touch locationInView: [touch view]];   
        start = [[CCDirector sharedDirector] convertToGL: start];
        CGPoint end = [touch previousLocationInView:[touch view]];
        end = [[CCDirector sharedDirector] convertToGL:end];
    
        // begin drawing to the render texture
        [target begin];
    
        // for extra points, we'll draw this smoothly from the last position and vary the sprite's
        // scale/rotation/offset
        float distance = ccpDistance(start, end);
        if (distance > 1)
        {
            int d = (int)distance;
            for (int i = 0; i < d; i++)
            {
                float difx = end.x - start.x;
                float dify = end.y - start.y;
                float delta = (float)i / distance;
                [brush setPosition:ccp(start.x + (difx * delta), start.y + (dify * delta))];
                [brush setRotation:rand()%360];
                float r = ((float)(rand()%50)/50.f) + 0.25f;
                [brush setScale:r];
                //[brush setColor:ccc3(CCRANDOM_0_1()*127+128, 255, 255) ];
                // Call visit to draw the brush, don't call draw..
                [brush visit];
            }
        }
        // finish drawing and return context back to the screen
        [target end];   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I need to draw a widget contents onto Bitmap. The code(pseudo)
Android Calendar App I need to be able to implement a view similar to
I need to draw a Gantt-Chart within my iPad App. Are there any frameworks
I'm developing an App, and I need to draw borders and separators on a
Say I have the following routes that are constrained to specific subdomains: App::Application.routes.draw do
In my App I need to draw graph data with different datamodels that frequently
in my app for WP7(mango) I need to navigate the user from one point
I need to implement a revision system for articles in my grails web app.
I have this devise routes in routes.rb file: app::Application.routes.draw do scope :locale, locale: /#{I18n.available_locales.join(|)}/
My app need to target API level 7 and above, however I'd like to

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.