Finger drawing

How can I achieve a finger drawing effect?
I've tried with CCDrawNode.DrawLine but there are performance issues and artifacts on the screen.
I also tried it with multiple Begin/End calls on a CCRenderTexture and i always get a completely black sprite...
A code sample would be nice :)

Answers

  • devdenisdevdenis PLMember
    edited November 2016

    I've managed to solve it.

    `var drawNode = new CCDrawNode();
    foreach (var drawInfo in _drawInfo)
    {
    if (!_lastLocations.ContainsKey(drawInfo.Owner))
    _lastLocations.Add(drawInfo.Owner, drawInfo.Point);

                var lastLocation = _lastLocations[drawInfo.Owner];
                var newPoint = drawInfo.Point;
    
                drawNode.DrawLine(lastLocation, newPoint, drawInfo.Color);
    
                _lastLocations[drawInfo.Owner] = drawInfo.Point;
            }
    
            if (Children?.Contains(_oldRenderTexture.Sprite) == true)
                RemoveChild(_oldRenderTexture.Sprite);
    
            var newRenderTexture = new CCRenderTexture(_contentSize, _textureSizeInPixels);
            newRenderTexture.BeginWithClear(CCColor4B.Transparent);
    
            //_oldRenderTexture.Sprite.AnchorPoint = CCPoint.Zero;
            _oldRenderTexture?.Sprite.Visit();
    
            drawNode.AnchorPoint = CCPoint.Zero;
            drawNode.Visit();
    
            newRenderTexture.End();
    
            AddChild(newRenderTexture.Sprite);
            newRenderTexture.Sprite.AnchorPoint = CCPoint.Zero;
            _oldRenderTexture = newRenderTexture;`
    
Sign In or Register to comment.