I’m working on an app that spawns many sprites with various ranges of properties. The list of properties is growing as I work on it. Properties values are passed through json, so there’s a deserialization process in the beginning, after which I have them stored in several arrays. Sprites spawn frequently. Each spawn I have to traverse the arrays to extract the needed values to process them and assign as sprite properties (e.g. find a range of numbers, get a random value from that range). I fear this method of data management is becoming rather inefficient, especially if I have 100+ sprites at the end of the day.
I would like to cache all the values somewhere right after deserializing from json for faster access and more efficient processing vs keeping everything in arrays. Is there way to do this in Libgdx?
This is a design issue and nothing to do with libGDX.
Say you have sprites/objects that represent aliens/monsters. Say you have 1000 types of aliens with texture regions, animations, sizes, velocities, etc. How do you store this data so that when you need to spawn an alien or a group of aliens, you can setup it as fast as you can in an update?
I’ve been thinking of a solution for this. I’d probably stick everything into a database. I don’t know how fast it would be to access the database to extract values.
Another option would be to pool the objects. This is especially helpful if you create and destroy always the same objects and pooling would really increase the performance. Libgdx has a built in Pool feature and is quite easy to use.
pool.obtain() gives you an object from the pool and pool.free() returns the object back to the pool.
I hope this is enough to solve your problem
Thanks for the tip. I think pooling might work