dmko Posted May 11, 2017 Share Posted May 11, 2017 I have some code which works just fine, but I'm not sure if there's a better way of drawing lines on the screen with a texture-brush and I also have a question about erasing Here's what I'm doing atm: SETUP Create a RenderTexture of a certain size ("renderTexture") Create a Sprite out of that, and add the Sprite to the stage ("viewSprite") Create a Container, don't add anything to it yet ("drawBuffer") Create an Array (or really object pool "pool") of sprites ("brushSprite") with the current brush texture (and other settings - color, size etc.). ("pool" - under the hood can grow, be reset when brush settings change, etc.) DRAW A LINE from p1:Point to p2:Point Calculate all the points we need to draw a line between the points (let's ignore this algorithm for now) Get that number of brushSprites from pool For each point - add a brushSprite to drawBuffer at that point When all the children are added, call renderer.render(drawBuffer, renderTexture, false); return all the used brushSprites to pool remove all the children from drawBuffer Here's my specific questions: Is adding the children to drawBuffer and then calling renderer.render() less often going to be more efficient than just renderer.render() each sprite directly? How can I sprinkle in an erase functionality to this? I'm only concerned about webgl if it matters, canvas support isn't absolutely necessary (and I mean true erase, like if there's an image underneath the viewSprite that image should bleed through - painting a solid color onto the renderTexture won't suffice Thanks! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.