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?
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.