我尝试使用 cocos2d 制作追踪手指游戏。
我移动我的手指写一个字母,结果是这样的:
http://www.freeimagehosting.net/m39l6
源代码:
-(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];
}
画法:
-(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);
}
}
我试过 glEnable(GL_LINE_SMOOTH)。但这在设备上不起作用。
知道如何修复红圈部分吗?
谢谢。