Austin
Austin

Reputation: 4929

Small issue with cocos2d sketch board

I'm trying to add a "whiteboard", so that people can draw lines on it.

The only problem is, if I draw very fast, it spaces the sprites pretty far away, so it's barely even legible if they are trying to draw letters or numbers. There's a ton of space between the different sprites.

Here's my method where most of the drawing is happening I think.

-(void) update:(ccTime)delta
    {
        CCDirector* director = [CCDirector sharedDirector];
        CCRenderTexture* rtx = (CCRenderTexture*)[self getChildByTag:1];

        // explicitly don't clear the rendertexture
        [rtx begin];

        for (UITouch* touch in touches)
        {
            CGPoint touchLocation = [director convertToGL:[touch locationInView:director.openGLView]];
touchLocation = [rtx.sprite convertToNodeSpace:touchLocation];

        // because the rendertexture sprite is flipped along its Y axis the Y coordinate must be flipped:
        touchLocation.y = rtx.sprite.contentSize.height - touchLocation.y;


        CCSprite* sprite = [[CCSprite alloc] initWithFile:@"Cube_Ones.png"];
        sprite.position = touchLocation;
        sprite.scale = 0.1f;
        [self addChild:sprite];
        [placedSprites addObject:sprite];
    }

    [rtx end];
}


Maybe this is the cause?

[self scheduleUpdate];  

I'm not entirely sure how to decrease the time between updates though.

Thanks in advance

Upvotes: 0

Views: 131

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

The problem is simply that the user can move the touch location (ie his/her finger) a great distance between two touch events. You may receive one event at 100x100 and the next the finger is already at 300x300. There's nothing you can do about that.

You can however assume that the change between two touch locations is a linear move. That means you can simply split any two touches that are farther apart than, say, 10 pixels distance and split them in 10 pixel distance intervals. So you'd actually generate the in-between touch locations yourself.

If you do that, it's a good idea to limit the minimum distance between two touches, otherwise the user could draw lots and lots of sprites in a very small area, which is not what you want. So you would only draw a new sprite if the new touch location is, say, 5 pixels away from the previous one.

Upvotes: 1

Related Questions