I’m working on a game for moblie platforms where memory is always a concern.
I’m using a base abstract class enemy. All other enemies will be variants of this class.
My initial intent is to store methods for updating the enemy in the base class, and then store the specific behaviors in each child enemy class.
My question is this: With possibly hundreds of enemies per load (or level), will I save memory writing all of my behaviors in one big class which each enemy refers to? In other words, does having hundreds of enemies, each of which has a boatload of behaior code, require much more memory than storing everything in a single reference class?
Initial Idea:
enemy.Update()
Memory saving idea:
//Static class is named EnemyBehavior
EnemyBehavior.UpdateEnemy(enemy)
Although each instance of your class has its own private, memory-consuming copies of its variables, it does not have separate copies of its method definitions. Methods consume memory per-class, not per-instance. That only makes sense, since it’s not possible for a class instance to change the definition of a method. So, sorry, but your idea won’t save any memory.