Brian
Brian

Reputation: 77

Need CCRenderTexture to render faster ios

I'm making a drawing app, and I'm having the users draw with CCRenderTexture. It basically keeps rendering a picture of a black circle to simulate drawing. When I move my finger slowly, it works really well since the circles come together to form a line. However, when I move my finger quickly, it ends up just being a bunch of circles that aren't connected (http://postimage.org/image/wvj3w632n/). My question is how I get the render texture to render the image faster or have it fill in the blanks for me.

Also, I'm not completely sold on this method, but it's what I've found while looking around. Feel free to suggest whatever you think would be better. I was originally using ccdrawline but it really killed my performance. Thanks!

Upvotes: 0

Views: 662

Answers (2)

Marine
Marine

Reputation: 1097

The gaps between start point and the end points need to be sorted out. I am pasting code that might help you to resolve the situation you showed in the link.

in .h file

CCRenderTexture *target;
CCSprite* brush;

in the init method of .m file

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

add the touches method I am showing the touchesMoved code.

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


        }
    }
}

Hopefully it would work for you.

Upvotes: 2

Ben Trengrove
Ben Trengrove

Reputation: 8769

Its not that CCRenderTexture draws too slow its that the event only fires so often. You do need to fill in the gaps between the touch points you receive.

There is a great tutorial here about it which you may have already seen, http://www.learn-cocos2d.com/2011/12/how-to-use-ccrendertexture-motion-blur-screenshots-drawing-sketches/#sketching

Upvotes: 0

Related Questions