2012-07-02 30 views
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。

回答

0

您使用的gl线条宽度大于iPhone上允许的最大宽度。当你超过这个数字时会发生这种情况,你会得到那些奇怪的加上形状。您需要做的就是使用CCRenderTexture像画笔一样连续绘制一个精灵。阅读本教程,特别是关于绘制草图的部分。

http://www.learn-cocos2d.com/2011/12/how-to-use-ccrendertexture-motion-blur-screenshots-drawing-sketches/#sketching

+0

嗯,如果我不断地画一个精灵,我快速地移动我的手指,这是会发生什么:http://www.freeimagehosting.net/74pqm –

+0

是的,你需要插值在不同触摸位置,以设定的时间间隔绘制点。 –

+0

是的,我试过catmull-rom插值,结果很棒。谢谢。 :D –