- Home /
How to save lines/strokes?
I'm trying to build a very watered-down version of ClipStudio and I'd like to have the option to undo strokes or delete whole lines (similar to OneNote) but I'm stumped on how to save a texture as a sprite.
Currently, my program is simply watching for when the mouse is clicked before it starts setting pixels. So,
1) I need to modify my program to figure out when a stroke ends
2) I need to figure out a way to save that stroke as a sprite
I'm currently running on a computer that doesn't have touchscreen so I thinking of using a boolean which is flips on/true when the user is drawing and off/false when the mouse button is no longer pressed. Is there a more efficient way to notice a stroke?
Now, the main conundrum. I've tried using NewSprite and Sprite.Create but the whole Rect thing is kind of confusing me. I've looked at the documentation for Create and Rect but I'm stumped as to how to use it with what I'm doing. The lines don't have a specific length or width so how could I use Rect? Also, when I attach the SpriteRender component to my canvas it seems to only save 1 sprite but I want to save a whole list of them.
Answer by michaelfelleisen · Jun 24, 2020 at 06:22 AM
depending on how complex your strokes are you could use the LineRenderer.
Everytime the user starts to draw a line you create a LineRenderer GameObject and feed it the line positions. And if the user is done with the line you put the linerenderer in a list somewhere.
If you want to undo lines, just destroy your linerenderer gameobjects off the list.