Hi, I’m trying to make a mechanic for players to build their own customizable spaceship in a 2d setting, and I’m realizing that as these ships get bigger, because I’m making them with pixel art from individually instantiated pixels, the game gets really laggy. I wanted to know if there was a way to optimize better. I was hoping I could through turning it all into a giant sprite but I can’t figure out how to do that.
You’d probably want to “photograph” the user’s work with a RenderTexture instead of making lots of micro sprites. That way the entire thing will be one texture ultimately.
You could retain info about all the sprites in your own data structures if you want to build colliders out of it, or edit it more.
I’m kinda curious to see what you’re building. Custom user art spaceships can be pretty cool, especially with some physics like parts connected by FixedJoint2D… hint: fixed joints can flex too and it’s pretty awesome for legs and deflector shields and really just about anything in a spaceship!
If you want a leg up on doing that, here’s my lottery scratcher: https://www.youtube.com/watch?v=N_Ia9_LpV2M
Full code / project at:
you need to use texture2d.setpixel,
this is very slow to execute, but if you can afford to make a small pause for “loading”, you will get a payoff after that because it will become just 1 object which is much less costly
The logic is that you pay a short time cost for the method to run in exchange for smooth sailing after that
instead of having many objects that never hang the game super hard, but create a stable low fps with bad performance
do you really have pixel by pixel added to the ship? or you have specific 2D modules like weapons or engines?