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 –