Tying it into the framework
We have covered a lot on the subject of drawing images with SDL but we have yet to tie everything together into our framework so that it becomes reusable throughout our game. What we will now cover is creating a texture manager class that will have all of the functions we need to easily load and draw textures.
Creating the texture manager
The texture manager will have functions that allow us to load and create an SDL_Texture
structure from an image file, draw the texture (either static or animated), and also hold a list of SDL_Texture*
, so that we can use them whenever we need to. Let's go ahead and create the TextureManager.h
file:
First we declare our
load
function. As parameters, the function takes the filename of the image we want to use, the ID we want to use to refer to the texture, and the renderer we want to use.bool load(std::string fileName,std::string id, SDL_Renderer* pRenderer);
We will create two draw functions,
draw
anddrawFrame
. They will both take...