Quartz NSBezierPath Adding points on the fly

Discussion in 'Mac Programming' started by neoserver, Sep 24, 2008.

  1. macrumors 6502

    Joined:
    Apr 24, 2003
    #1
    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 :)
     

    Attached Files:

  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Change the body of your loop to this:
    Code:
    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:
     
  3. thread starter macrumors 6502

    Joined:
    Apr 24, 2003
    #3
    THANK YOU! That was the ticket!
     

Share This Page