- Home /
Combining multiple sprites
I am making a game where there are a lot of blood sprites, dead bodies. Each bullet hit instantiates new blood sprite object and eventually game starts to lag. How can i combine all these blood, dead bodies sprites into one big sprite or texture? I would like effect like in Crimsonland, where u can have infinite amount of blood sprites, dead bodies.
Answer by LMan · Apr 18, 2015 at 09:04 PM
I would suggest an object pool pattern.
Basically, keep a large number of sprites already instantiated in the level, but deactivated. Rather than instantiate a new object (which you might be finding expensive), simply reposition and activate an object from the pool. You can then fade the opacity over time, deactivate, and put the object back in the pool after it's no longer needed.
As far as combining the sprites, you'll want to look at batching
if you use an image editing program, (ie. Gimp, Photoshop, perhaps even MS Paint.) You can put all the sprites on the same texture file. This will cause many of the draw calls to anything on that one texture file to "Batch." Which will save you processing power.
Answer by nasa8 · Mar 15, 2016 at 01:38 PM
This is quite challenging task I suppose. I think of two options:
1) You can combine all the spilt blood into one sprite
2) Combine blood into one texture for multitextured (may be triplanar) terrain or something
The first way is easier to implement I think. If I were in your shoes I would try to combine all small sprites into bigger one changing it's texture dynamically by SetPixels method. Read texture of a small blood sprite by GetPixels, then calculate the offset for your big sprite and put there your change using SetPixels.
You can find the description of Set/GetPixels in Unity Scripting Manual.
Your answer
Follow this Question
Related Questions
Difference between Sprite and Default texture types? 0 Answers
Sprite Editor Problems 2 Answers
Are shaders more efficient than manual pixel replacement? 0 Answers
Compine 4 sprites into one big image 0 Answers
Assigning UV Map to model at runtime 0 Answers