Cleaning up the house
We have a pretty complete game. Sure, it's not going to set any records or make anyone rich, but if this is your first game, then congratulations!
We have been remiss in one area: good programming dictates that any time we create an object, we delete it when we are done using it. Up to now, you may be wondering if we were ever going to do this! Well, now is the time.
We made a placeholder for all of these operations in the EndGame
function. Now, we will add the necessary code to properly release our resources.
Release sprites
Let's start by clearing out our sprites. It is important to remember that when we remove any resource, we need to make sure that it is also releasing its own resources. This is the purpose of the class destructor. Let's use the Sprite
class as an example. Open Sprite.cpp
and you should see a destructor defined using the following code:
Sprite::~Sprite() { for (int i = 0; i < m_textureIndex; i++) { glDeleteTextures(1, &m_textures[i]);...