I went down this same path, but let me tell you that the RenderTexture route will be an issue, because you won't be able to erase points from the path (it'll be pre-rendered).
Also, the texture can get huge on iPad and lead to major performance issues (1024x768 render texture = painful).
What I did was implement my own CCNode object and overrode the draw() method to use ccDrawPoly.
Each touch, then, calls an "addWaypoint" method (not shown) on the node that adds the CGPoint to the waypoint array, and also interpolates additional points to add that curve the line between the existing points and the new touch.
The interpolation is done using a quadratic lagrange curve algorithm, see this post: http://www.cocos2d-iphone.org/forum/topic/4853#post-28918
For drawing and moving the object along the path, I used the following code:
- (void) draw {
// Draw the curve line
if (waypointIndex > 0 ) {
if (active) {
glColor4f(1.0, 0.0, 0.0, 1.0);
glLineWidth(4.0f);
} else {
glColor4f(0.9,0.9,0.9,0.9);
glLineWidth(1.0f);
}
int startPoint = nextObjectWaypointIndex - 1;
if (startPoint < 0)
startPoint = 0;
if (startPoint > waypointIndex)
startPoint = waypointIndex;
ccDrawPoly(&waypoints[startPoint], waypointIndex - startPoint , NO);
}
}
Then, it has a reference to another CCNode that is the sprite to move along the path, and uses CCSequence to move the object and then call itself again:
- (void) moveObjectAlongPath {
if (self.dying || speed <= 0)
return;
self.objectMoving = YES;
if (nextObjectWaypointIndex > 2 && nextObjectWaypointIndex >= waypointIndex) {
// Object has reached end of path
[self complete];
} else {
// Calculate duration and speed
CGPoint nextWaypoint = waypoints[nextObjectWaypointIndex];
nextObjectWaypointIndex++;
CGFloat duration = ccpDistance(self.object.position, nextWaypoint) / speed;
CGPoint difference = ccpSub(nextWaypoint,self.object.position);
double angle = -1 * (atan2(difference.y, difference.x) * 180 / M_PI + 90) + 180;
[self.moveAction initWithDuration:duration position:nextWaypoint];
[self.rotateAction initWithDuration:duration angle: angle];
CCSequence *actionSequence = [CCSequence actions:
[CCSpawn actions:
moveAction,
rotateAction,
nil],
callAgainAction,
nil];
[self.object runAction:actionSequence];
}
}