The RenderManager class definition

All this time, we have been moving around our level without a background. This was fine in previous chapters, where our level fitted exactly onto the canvas element. Now, however, we are scrolling around our level with a camera. If nothing is moving in the background, it can be hard to tell whether your spaceship is moving at all. To create the illusion of movement in our game, we will need to add a background renderer. In addition to that, we want all rendering in our game to be done using the camera we just created as an offset. Because of this, we no longer want our game objects to call SDL_RenderCopy or SDL_RenderCopyEx directly. Instead, we have created a RenderManager class that will take responsibility for performing the rendering from within our game. We have a RenderBackground function that will render a starfield as a background, and we have created a Render function that will render our sprite textures using the camera as an offset. This is what the RenderManager class definition looks like:

class RenderManager {
public:
const int c_BackgroundWidth = 800;
const int c_BackgroundHeight = 600;
SDL_Texture *m_BackgroundTexture;
SDL_Rect m_BackgroundDest = {.x = 0, .y = 0, .w =
c_BackgroundWidth, .h = c_BackgroundHeight };

RenderManager();
void RenderBackground();
void Render( SDL_Texture *tex, SDL_Rect *src, SDL_Rect *dest, float
rad_rotation = 0.0, int alpha = 255, int red = 255, int green =
255, int blue = 255 );
};

The last thing we need to do in the game.hpp file is to create an external link to two new object pointers of the Camera and RenderManager types. These will be the camera and render manager objects that we will be using in this version of our game engine and are external references to variables that we will define inside our main.cpp file:

extern Camera* camera;
extern RenderManager* render_manager;
extern Locator* locator;