i try to make a tracing finger game using cocos2d.
i move my finger to write an alphabet, the result is this:
http://www.freeimagehosting.net/m39l6
the source code:
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector]convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
NSValue *oldVal = [NSValue valueWithCGPoint:oldTouchLocation];
NSValue *val = [NSValue valueWithCGPoint:touchLocation];
[trails addObject:oldVal];
[trails addObject:val];
}
draw method:
-(void)draw{
for (int i=0; i<trails.count-1; i++) {
origin = ((NSValue *)[trails objectAtIndex:i]).CGPointValue;
destination = ((NSValue *)[trails objectAtIndex:i+1]).CGPointValue;
ccDrawLine(origin, destination);
}
}
i’ve tried glEnable(GL_LINE_SMOOTH). but that’s not working on the device.
any idea how to fix the red-circled parts?
thx.
The gl line width you are using is greater than the max allowed on the iPhone. This is what happens when you exceed that number, you get those strange plus shapes. What you need to do instead is draw a sprite continuously like a paintbrush using CCRenderTexture. Have a read of this tutorial, in particular the part about drawing sketches.
http://www.learn-cocos2d.com/2011/12/how-to-use-ccrendertexture-motion-blur-screenshots-drawing-sketches/#sketching