Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hodgey87

Guest
Original poster
Mar 20, 2009
41
0
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:

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
 
Code:
for(mdelegate.pointarray)
{
		
}

A for loop is probably the best way to do it but that code is not syntactically correct.

Yeh this is the area i get stuck in all these arrays

Code:
for (firstpointx = firstpointy ; secondpointx = secondpointy; )
		{
			mdelegate.pointarray = [NSMutableArray alloc];
		}

i saw an example like this
 
Looping is a basic fundamental of any programming. I suggest you step back from the real coding and go learn those before you continue with this project.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.