Game Object Design
- by oisin
I'm having a problem with the way I designed my first simple game in C++.
I have GameObject (abstract class) and ObjectA which inherits the update() and draw() methods from GameObject.
My main loop contains a linked list of GameObject*, and while that list is not empty it cycles through it, calling update on each one.
Up until this point, I thought the design was standard(?) and would work.
However, when I call update on ObjectA() I run into two problems:
ObjectA can die which messes up the list, which in turn throws off the loop in main.
ObjectA can spawn more ObjectA's but these are local scope and the update() goes out of scope, creating problems in main's list of GameObjects.
I think my design if alright, but I'm having such problems with segmentation faults that there must be something seriously wrong with at least one part of my implementation. If anyone could point out any serious mistakes or simple examples of this being done (or even alternative designs) then I would greatly appreciate it!