PDA

View Full Version : Quartz NSBezierPath Adding points on the fly




neoserver
Sep 24, 2008, 11:25 PM
Here's the background:

I want to be able to have an array of points and then draw line segments between these points starting at (0,0).

So what I do is add points to the array, and then send a setNeedsDisplay:YES to my custom View.

In the drawRect: function, I create a NSBezierPath and loop through the NSMutableArray and by using lineToPoint, I am able to create the effect I want.

HOWEVER, after about 3 Points, I get a line connecting the last point drawn to the origin (NOT WANTED).

This is my first time working with NSBezierPaths, So I'm sure theres just something I've Overlooked.

I've also attached the project I'm using.

Any Ideas? Thanks in Advance :)



kainjow
Sep 25, 2008, 12:13 AM
Change the body of your loop to this:
lastpoint = [[dataPoints objectAtIndex:i] pointValue];
if (i == 0)
[apath moveToPoint:lastpoint];
else
[apath lineToPoint:lastpoint];

You don't need to moveToPoint: each time. The path's current point is set to the point passed to lineToPoint:

neoserver
Sep 25, 2008, 12:36 AM
Change the body of your loop to this:
lastpoint = [[dataPoints objectAtIndex:i] pointValue];
if (i == 0)
[apath moveToPoint:lastpoint];
else
[apath lineToPoint:lastpoint];

You don't need to moveToPoint: each time. The path's current point is set to the point passed to lineToPoint:

THANK YOU! That was the ticket!