0
我尝试使用cocos2d制作一个跟踪手指游戏。如何使ccdrawline在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)。但这不适用于该设备。
任何想法如何解决红圈部分?
thx。
嗯,如果我不断地画一个精灵,我快速地移动我的手指,这是会发生什么:http://www.freeimagehosting.net/74pqm –
是的,你需要插值在不同触摸位置,以设定的时间间隔绘制点。 –
是的,我试过catmull-rom插值,结果很棒。谢谢。 :D –