How can I redraw an image over a specific memory location?

I’m looking for a way to do a star filled sky that randomly generates the stars.

As of right now I’m creating random sprites off of an atlas and moving them randomly as they move out of view.

It works okay, but it’s definitely impacting my fps and I’m sitting around 60, but I’m also on a laptop and am not sure I can get that on a mobile device.

Anyway, I’m thinking it may be easier to draw an image by scattering the stars on it then re-draw it when it jumps up so it only tracks the transform of the image rather than thousands of sprites.

Problem is, I can only think of how to make a new image, rather than rewriting over the same memory. So that would kick in the GC instantly. Not good.

I’m also considering trying to use a particle generator, but I’m not even sure where to start with that.

Any suggestions?

I don’t understand why you can only make a new image… once you have a Texture2D, you can draw into it as many times as you like.

You could even use PixelSurface if you want it to be easy. :wink: In fact, using a PixelSurface “LivePixel” for each star, this might be a decent solution.

But probably the best would be to use something like Vectrosity in point mode.

Vectrosity is one of the best asset purchases I’ve ever made — it’s not that I can’t find any nits to pick with it, but none of them are show-stoppers, and it does what it does really well. (Note that you can buy it from their store, or via the Asset Store, whichever you prefer.)

1 Like

A particle system would work with a little trick: in the modules of a Particle System, you can setup a Texture Sheet Animation module to choose a random sprite per particle. The trick is to create your spritesheet in one large column, so that you can use “Single Row” setting with “Random Row” checked. Then it is possible to create particles that don’t move, and last indefinitely. Or continue to generate more as the camera pans, etc.

Both of those sound tempting, but I think I need to work out a solution on my own for learning purposes. Also, the wife would kill me if I bought another asset. :smile:

Yeah, but the problem is that the camera is constantly panning up and I would want to clear the particles out so it doesn’t eat up my memory.

That could be done using the MaxParticles setting I think. You can set it to maybe double or triple what you expect in a single screen, so that you never see the particles being removed.