Callbacks and set up for classes derived from Drawable. More...
Detailed Description
Callbacks and set up for classes derived from Drawable.
Drawable GameObjects allow the user to execute code once every draw frame. This is done through the pure virtual Drawable::Draw() function that the user overrides.
The DrawableManager keeps track of all Drawable GameObjects in the scene. In order for the DrawableManager to call the Drawable::Draw() function, the user first needs to register the current Drawable GameObject. This is done through the Drawable::Register() function. Likewise, the user can deregister the current Drawable GameObject from the DrawableManager with the Drawable::Deregister() function. This prevents the Drawable::Draw() function from being called on a Drawable GameObject that shouldn't be drawn anymore.
For example, lets assume we have a bullet class. Since the bullet should be visually seen, it needs to be drawn to the screen.
Bullet.h:
Bullet.cpp:
First, in the header file, the bullet class derives from the Drawable class and overrides the Drawable::Draw() function. Since Drawable virtually inherits from GameObject, bullet is also a GameObject.
Next, in the .cpp, the bullet calls the render function on its GraphicsObject within the Drawable::Draw() function. It's also registered to the DrawableManager within the GameObject::SceneEntry() function and it's deregistered from the DrawableManager in the GameObject::SceneExit() function.
For drawing 2D sprites, the same setup is required HOWEVER all 2D sprites (IonSprites) need to be rendered in Drawable::Draw2D() instead of Drawable::Draw()
Classes | |
class | Drawable |
A virtual derived class of GameObject that allows the GameObject to be drawn. More... | |