Problem with classes/multiple inheritence

sadfg
Last edited on
I've been doing a lot of this lately, and asked help about similar stuff as well.
Let's say you have the parent class GameObject and child classes player and enemy. Both children need a position, a velocity, a sprite or equivalent, and methods such as update() and render(). This can all go in GameObject. Anything required for those functions has to be either in the GameObject class or in subclasses - in this case GameObject is virtual. That's what I have since some objects in my game have sprites while others are drawn using shapes.

Having an ID to represent the type of entity makes things more complex. You should read about dynamic casting, it's a very powerful feature of C++ which allows you to test if a pointer to a GameObject actually points a player or an enemy or wall... If the dynamic cast returns a null pointer, it's because it's not an instance of that subclass.

As for the specific problem you have there, it's either because the camera should be the one drawing instances or the object could have a pointer to the camera.
Topic archived. No new replies allowed.