Я рисую много линий, чтобы дать эффект среза и удаленные точки одновременно из этого изменяемого массива, где я помещаю точку для рисования линии
код: -
-(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];
}