0

我正在制作一个绘图应用程序,并且让用户使用 CCRenderTexture 进行绘图。它基本上一直在渲染一个黑色圆圈的图片来模拟绘图。当我慢慢移动我的手指时,效果非常好,因为圆圈聚集在一起形成一条线。但是,当我快速移动手指时,它最终只是一堆未连接的圆圈(http://postimage.org/image/wvj3w632n/)。我的问题是如何获得渲染纹理以更快地渲染图像或让它为我填补空白。

另外,我对这种方法并不完全满意,但这是我环顾四周时发现的。随意提出任何你认为会更好的建议。我最初使用的是 ccdrawline,但它确实扼杀了我的表现。谢谢!

4

2 回答 2

2

起点和终点之间的差距需要理清。我粘贴的代码可能会帮助您解决链接中显示的情况。

在 .h 文件中

CCRenderTexture *target;
CCSprite* brush;

在.m文件的init方法中

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];

添加我正在显示 touchesMoved 代码的 touches 方法。

-(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];


        }
    }
}

希望它对你有用。

于 2012-08-23T05:17:30.347 回答
0

并不是说 CCRenderTexture 绘制得太慢,而是事件只会如此频繁地触发。您确实需要填补您收到的接触点之间的空白。

这里有一个很棒的教程,你可能已经看过了,http://www.learn-cocos2d.com/2011/12/how-to-use-ccrendertexture-motion-blur-screenshots-drawing-sketches/#素描

于 2012-08-23T04:41:09.570 回答