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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:40:17+00:00 2026-06-07T00:40:17+00:00

Given an NSMutableArray of dynamic CGPoint s, what is the fastest and most efficient

  • 0

Given an NSMutableArray of dynamic CGPoints, what is the fastest and most efficient way to draw lines from array[0] to array[1], array[1] to array[2], etc.? Should I rewrite my function in C or C++ for better performance? Currently my framerate suffers dramatically when there are more than ~20 points in the array. I am using cocos2d v2.0.0-rc2 and I currently have:

-(void)draw
{
    for (int i = 0; i < [points count]; i+=2)
    {
        CGPoint startFromArray = [[points objectAtIndex:i] CGPointValue];
        CGPoint endFromArray = [[points objectAtIndex:i+1] CGPointValue];

        ccDrawLine(startFromArray, endFromArray);
    }

    [super draw];
}
  • 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-07T00:40:18+00:00Added an answer on June 7, 2026 at 12:40 am

    There’s no need to use iteration here. Cocos2d has a built-in function called ccDrawPoly(). You can use it like this:

    CGPoint *verts = malloc(sizeof(CGPoint) * [points count]);
    
    for (int i = 0; i < [points count]; i++) {
        verts[i] = [[points objectAtIndex:i] CGPointValue];
    }
    
    ccDrawPoly(verts, [points count], NO);
    
    free(verts);
    

    Obviously, you’ll get even better performance if you store your CGPoints in a C array instead of boxing and unboxing them from NSValues, but if you really need the mutability, that can’t be helped.

    As for the third argument of ccDrawPoly(), setting it to YES will connect the start and end points of the array, making a closed polygon, while using NO will just make a bunch of open lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I pull a specified number of items from NSMutableArray at a given
I create my NSMUtableArray the following way: self.myArray = [NSMutableArray array]; for (int i
Given these two queries: Select t1.id, t2.companyName from table1 t1 INNER JOIN table2 t2
Given an interface or interfaces, what is the best way to generate an class
NSMutableArray*array = [[NSMutableArray alloc]init]; NSArray*Somearray = [NSArray arrayWithObjects:1st Object,2ndObject,3rd Object,4th object,5th Object,nil]; In the
Given a basic key/value array, I'm wanting to store two sorted arrays based on
I accessed the Data from sqlite file as NSMutableArray[model_Array] in which I have duplicates
I am trying to remove all the objects from the NSMutableArray and I am
I have the following method: -(void)testAPIModule { self.requests = [NSMutableArray array]; NSLog(@making arrays); /*(A)*/
I have to print NSMutableArray *lstAirports; my array of object it print all record

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.