To,
TouchGameDev....
Hi,
I am able to draw the line using ccDrawLine method. I am collecting points on ccTouchesMoved method and add them to an NSMutable array. Then later in ccTouchesEnded, I am adding that NSMutable array to another NSMutable array. After that I add the CCNode as [self addChild:[DrawLine node]].
DrawLine the class inherited from a CCNode. Here I have written a -(void)draw method to draw line.
My problem is that when I draw the 2nd line, the 1st line gets deleted and 2nd line gets drawn.
I want all the lines which I am drawing should remain there till the time I delete them.
Can you please help me on this...
The code I have written is as follow.....
Please have a look at following code and please let me where I am making a mistake.
Is there any other way doing this?
Please help.
waiting for your reply..
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
lastLocation = [ myTouch previousLocationInView: [myTouch view]];
CGPoint point = [[CCDirector sharedDirector] convertToGL:location];
newPoint = point;
NSString *coordPt = [NSString stringWithFormat:@"%@", NSStringFromCGPoint(point)];
[persistance_obj->cgPointArray addObject:coordPt];
}
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self addChild:[drawLine node]];
NSMutableArray * tempArray = [[NSMutableArray alloc]init];
tempArray = [persistance_obj->cgPointArray copy];
[drawPath addObject:tempArray];
[tempArray release];
[persistance_obj->cgPointArray removeAllObjects];
}
-(void)draw
{
//persistance_obj = [persistance loaded];
drawFlag = 1;
glEnable(GL_LINE_SMOOTH);
glLineWidth(2.0f);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
int x;
if(indexVal > 0)
{
x = indexVal - 1;
}
else
{
x = indexVal;
}
NSArray *array = [drawPath objectAtIndex:x];
for(int i = 0; i < [array count]; i++)
{
lastLocation1 = CGPointFromString([array objectAtIndex:i]) ;
if(i+1 < [array count])
{
endPoint1 = CGPointFromString([array objectAtIndex:i+1]);
}
else
{
endPoint1 = CGPointFromString([array objectAtIndex:i]);
}
ccDrawLine(lastLocation1, endPoint1);
}
}