2011-02-09 104 views

回答

1

我绘制多行,得到切片的效果,并且同时从该可变数组移除点,其中i把点来绘制线

代码: -

-(void)init 
    { 
    [self checkAllArray]; 
    [self schedule:@selector(removePoints:) interval:0.0001f]; 
    } 
-(void)checkAllArray 
{ 
    if (naughtytoucharray==NULL) 
     naughtytoucharray=[[NSMutableArray alloc] init]; 
    else 
    { 
     [naughtytoucharray release]; 
     naughtytoucharray=nil; 
     naughtytoucharray=[[NSMutableArray alloc] init]; 
    } 
} 

-(void)draw 
{ 
    glEnable(GL_LINE_SMOOTH); 
    glColor4ub(255, 255, 255, 255); //line color 
    //glLineWidth(2.5f); 
    for(int i = 0; i < [naughtytoucharray count]; i+=2) 
    { 
     CGPoint start = CGPointFromString([naughtytoucharray objectAtIndex:i]); 
     CGPoint end = CGPointFromString([naughtytoucharray objectAtIndex:i+1]); 
       ccDrawLine(start, end); // line 1 
     ccDrawLine(ccp(start.x-2,start.y-2),ccp(end.x-2,end.y-2));// line 2 
     ccDrawLine(ccp(start.x-4,start.y-4),ccp(end.x-4,end.y-4));// line 3 
     ccDrawLine(ccp(start.x-6,start.y-6),ccp(end.x-6,end.y-6));// line 4 
     ccDrawLine(ccp(start.x-8,start.y-8),ccp(end.x-8,end.y-8));// line 5 
    } 
} 

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    CGPoint new_location = [touch locationInView: [touch view]]; 
    new_location = [[CCDirector sharedDirector] convertToGL:new_location]; 
    CGPoint oldTouchLocation = [touch previousLocationInView:touch.view]; 
    oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation]; 
    [naughtytoucharray addObject:NSStringFromCGPoint(new_location)]; 
    [naughtytoucharray addObject:NSStringFromCGPoint(oldTouchLocation)]; 
} 

-(void)removePoints:(ccTime *)tm 
{ 
    if ([naughtytoucharray count]>0) 
    { 
     [naughtytoucharray removeObjectAtIndex:0]; 
    } 
} 

-(void)dealloc 
{ 
    //NSLog(@"deallocing lightning\n"); 
    [self removeAllChildrenWithCleanup:YES]; 
    [super dealloc]; 
} 
0

您在屏幕空间得到几个控制点。然后插入它们并构建沿着该曲线的多个多边形。你可以使用片段着色器来绘制边框或纹理(但我认为它会更困难)。