Instantiating 1000+ sprites

Hi,
Im working on a painting book project.
I have coupe of brushes.
One is, I instantiate prefabs on mouse position to draw. But with time I face with performance issues. Because there are a lot of intanstiated object on the screen. Tris and verts increase a lot if user draws a lot of things.
Is there a way to achieve this issue?

Yes, you shouldn’t be instantiating sprites to paint. You should instead be updating a texture. PixelSurface (an asset I offer through the Asset Store, as well as on DigitalGift.Shop) is designed for this sort of thing, if you don’t want to work out the code to update a texture yourself.

Best,

  • Joe

Hi Joe,
Thank you for your reply.
I can update textures by pixel. But how can I do that for a shape. I mean I can update pixels under mouse pos but how can I change pixels like shape ( brush) I use?

Use a loop (or a pair of nested loops) to update many pixels at once. For a simple square brush, just loop from (mousePos - halfWidth) to (mousePos + halfWidth) on both X and Y. For a round brush, only update pixels that are within brushRadius of mousePos. Etc.

But the problem is my brushes are not simply shaped. I attached one of them.

3327599--259275--Brush.png

In that case you’ll want to draw the brush texture into the painting texture. You still do this with a double loop, just copying the pixels where the brush texture alpha is nonzero (or, applying paint in proportion to the alpha value).