Hello all… I have a couple of noob performance questions that I wanted to ask about before I went about making drastic changes to my code.
First, does using a singleton class drastically reduce performance? Would it be a huge mistake to use one in a step routine that updates every frame to check for collisions?
Basically, the code I’m using for enemy movement is getting a little too complex and I’d like to move it out of my game scene and into the enemy class itself. Since the movements are based on the positions of the other enemies (so they don’t collide with each other) I was thinking of creating a singleton class to keep track of all the sprites in the scene. Would this be okay?
My other question is along these same lines… I currently have a step method in the game scene that has a nested loop to determine if any enemies are near collision with each other. Considering my game should have no more than 6 enemies active at a time, this seems to run fine despite the O(n^2) running time. If I move the code into my enemy class, I would need a selector method running a single loop in each enemy instance… Should I expect a comparable running time?
I realize the fact that I’m only using a limited number of sprites should make both of the above cases work… but what if I were theoretically to have 100 sprites?
Thanks in advance for any clarification!