When I started building my Space Invaders clone, I considered the movement of the grid of enemies and thought, "Well, it sure seems inefficient to loop through this table of enemy objects, update them all, and then render them all. What if I put them in a container and then moved the container instead? When the container moves, the enemies will move."
However, I quickly learned that moving the container did not result in the enemy objects moving. Which made sense after I thought about them being different objects.
Next, I set the enemy object up so each was instantiated with an x-position that was something like this...
Code: Select all
self.x = 20 + container.x
This brought me all the way back to the start. If I have to update the position of every enemy and render it, then I don't think placing them in a container is gaining me any efficiency.
My question is this...is there a more efficient way to render and move a collection of objects than looping through each instance? I'm not worried about making my Space Invaders clone work...I can do that. I'm considering the general approach and how it will (or will not) scale up to larger instance collections. In essence, I'm using this clone as a way to identify "better" practices before I try to tackle a larger project.
Edited for clarity