Hi,
I use a grid of lines for my game logics. for debugging I would like to draw the actual lines on the map so that i can see whats happening.
I am trying to have these lines drawn using custom textures drawn by coregraphics using a block.
The "line"-objects have a method where the draw themselves in a passed CGContectRef. However it is not working. Might I be referencing the object the wrong way; because the drawing method only gets called once (per line).
Or is this approach not even possible?
code:
//adding the line and creating the custom texture
-(void)addLine:(Line *)line{
[boundries addObject:line];
id bLine = line;
CGRect frame = [[UIScreen mainScreen] bounds];
SPTexture *tex = [[SPTexture alloc] initWithWidth:frame.size.width
height:frame.size.height
draw:^(CGContextRef context){
[(Line *)bLine drawLineInContext:context];
}];
[self addChild:[SPImage imageWithTexture:tex]];
[tex release];
}
//draw the line in a cgcontextreference
-(void)drawLineInContext:(CGContextRef)ref{
CGContextSetRGBStrokeColor(ref, 1.0f, 0.0f, 0.0f, 1.0f);
NSEnumerator *e = [linePoints objectEnumerator];
NSValue *pointValue = [e nextObject];
CGPoint point = [pointValue CGPointValue];
CGContextMoveToPoint(ref, point.x, point.y);
while (pointValue = [e nextObject]) {
point = [pointValue CGPointValue];
CGContextAddLineToPoint(ref, point.x, point.y);
}
NSLog(@"drawn");
}