Sign in to follow this  
Dante12129

OOP Theory

Recommended Posts

Dante12129    2038

I am creating a simple framework in C++ to help me use RAII with SDL and make some functions easier.

 

  I am wondering about some classes and the Single Responsibility Principle, however. I have a screen class that basically encapsulates and SDL_Surface for the screen, but I'm wondering whether to have a function to access this pointer and then have a renderer class apply an image to that or have a function to put an image on the screen and have the renderer class use that. I'm also wondering whether the user should call an update function in the renderer class that calls an update function in the screen class, or just have the user call the screen's update function.

Share this post


Link to post
Share on other sites
EWClay    659
In terms of the basic rendering, I would just have a function to set the screen as a render target, and then functions to render to the current screen. There isn't much reason to link these things together.

What do you mean by updating the screen? It's a good idea to have a framework that allows you to plug different sections of the game such as menu screens into the main update/render loop. In this case the call to update would be coming from the application, not the user code.

Share this post


Link to post
Share on other sites
Dante12129    2038
What I mean by screen is the window that SDL creates, so updating it is basically calling SDL_Flip on it. I'm thinking of having a gamestate abstract base class upon which to build the different things such as the menu screen and actual gameplay and have the renderer render the parts associated with each state.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this