2012-07-02 32 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 –