Hi Guys,
Just wondered if anyone could help, currently developing a join the dots type app but have a little trouble. I need to be able to keep all the lines that are drawn on the screen.
Currently i can draw 1 line and when i draw the next the previous line disappears. I know i need to store these points in an array and call them but im not sure how to go about doing this.
If someone could help id appreciate it.
Heres the code for the drawing:
Many thanks
Just wondered if anyone could help, currently developing a join the dots type app but have a little trouble. I need to be able to keep all the lines that are drawn on the screen.
Currently i can draw 1 line and when i draw the next the previous line disappears. I know i need to store these points in an array and call them but im not sure how to go about doing this.
If someone could help id appreciate it.
Heres the code for the drawing:
Code:
if([mdelegate.pointcollectionarray count]==4)
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(ctx, [UIColor blackColor].CGColor);
CGContextSetLineWidth(ctx, 6.0);
float firstpointx= [[mdelegate.pointcollectionarray objectAtIndex:0] floatValue];
float firstpointy= [[mdelegate.pointcollectionarray objectAtIndex:1]floatValue];
float secondpointx= [[mdelegate.pointcollectionarray objectAtIndex:2]floatValue];
float secondpointy= [[mdelegate.pointcollectionarray objectAtIndex:3]floatValue];
CGContextMoveToPoint(ctx,firstpointx,firstpointy);///move to your first dot
CGContextAddLineToPoint(ctx, secondpointx, secondpointy);//add line from first dot to second dot
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextStrokePath(ctx);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
[mdelegate.pointcollectionarray removeAllObjects];
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if(!mdelegate){
mdelegate = (Dot2DotAppDelegate*)[[UIApplication sharedApplication]delegate];}
if(!mdelegate.pointarray){
mdelegate.pointcollectionarray=[[NSMutableArray alloc] init]; }
//NSLog(@"touched");
CGPoint curPoint = [[touches anyObject] locationInView:self];
[mdelegate.pointcollectionarray addObject:[NSNumber numberWithFloat:curPoint.x]];
[mdelegate.pointcollectionarray addObject:[NSNumber numberWithFloat:curPoint.y]];
[self setNeedsDisplay]; // calls drawRectMethod
}
Many thanks