2012-08-22 25 views
0

我做的繪圖應用程序,我在用戶與CCRenderTexture借鑑。它基本上保持渲染一個黑色圓圈的圖片來模擬繪圖。當我慢慢地移動手指時,由於圈子聚集在一起形成一條線,所以它運作得非常好。然而,當我快速移動我的手指,它最終只是被圈了一堆沒有連接(http://postimage.org/image/wvj3w632n/)。我的問題是我如何獲得渲染紋理來更快地渲染圖像或使其填充空白。需要CCRenderTexture呈現更快的ios

而且,我不是完全靠這種方法出售,但它同時環顧四周我找到什麼了。隨意提出你認爲會更好的建議。我最初使用ccdrawline,但它真的殺死了我的表現。謝謝!

回答

2

起點和終點之間的差距需要進行清理整頓。我粘貼的代碼可能會幫助您解決您在鏈接中顯示的情況。

在.h文件中

CCRenderTexture *target; 
CCSprite* brush; 
在.m文件

target = [[CCRenderTexture renderTextureWithWidth:size.width height:size.height] retain]; 
[target setPosition:ccp(size.width/2, size.height/2)]; 
[self addChild:target z:1]; 
brush = [[CCSprite spriteWithFile:@"brush_i3.png"] retain]; 

的init方法

添加觸摸方法,我表示touchesMoved代碼。

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint start = [touch locationInView: [touch view]]; 
    start = [[CCDirector sharedDirector] convertToGL: start]; 
    CGPoint end = [touch previousLocationInView:[touch view]]; 
    end = [[CCDirector sharedDirector] convertToGL:end]; 
    printf("\n x= %f \t y= %f",start.x,start.y); 
    float distance = ccpDistance(start, end); 
    if (distance > 1) 
    { 
     int d = (int)distance; 
     for (int i = 0; i < d; i++) 
     { 
      float difx = end.x - start.x; 
      float dify = end.y - start.y; 
      float delta = (float)i/distance; 

      [brush setPosition:ccp(start.x + (difx * delta), start.y + (dify * delta))]; 
      [target begin]; 
      [brush setColor:ccc3(0, 255, 0)]; 

      brush.opacity = 5; 
      [brush visit]; 
      [target end]; 


     } 
    } 
} 

希望它能爲你工作。

+0

偉大的作品!我想贊成票你,如果我能...另外,就行了「如果(距離> 1)」我做到了「如果(距離> 0.1)」,這樣慢運動也將借鑑。 – Brian

+0

@布萊恩好東西。我沒有爲緩慢的觸摸測試,但聽起來不錯。我也會使用那個並測試它。 – Marine