问题
I'm new to game development, SDL and C++. I have been learning with the code here:
http://gamedevgeek.com/tutorials/managing-game-states-in-c/
The relevant bit:
Multiple states are not only important in demos, but also in games in general. Every game starts off in an introduction state, then moves to a menu of some kind, a finally play begins. When you’re finally defeated, the game moves to a game-over state, usually followed by a return to the menu. In most games it is possible to be in more than one state at a time. For example, you can usually bring up the menu during game play.
My question is: To have multiple states display at once, such as displaying a menu on top of game play, must each state have it's own Renderer?
回答1:
You pass an Image.png*(or other format) onto a Texture, Then you place the Texture on a "surface"(you can clip the texture with this) which is then passed onto a Renderer. So, all you have to do is change the clip and texture, and pass it to the Renderer In the !RIGHT ORDER!
Example: You would Render the background first, and then Sprites, and then Effects, etc...
I hope this helps.
BELOW CODE WAS TAKEN FROM LAZY FOO WEBSITE!! CHECK IT OUT VERY USEFULL TO BEGIN SDL2
http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php
//While application is running
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 )
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
}
//Clear the last frame
SDL_RenderClear( gRenderer );
//Render texture to screen
SDL_RenderCopy( gRenderer, gTexture1, NULL, NULL );
SDL_RenderCopy( gRenderer, gTexture2, NULL, NULL );
SDL_RenderCopy( gRenderer, gTexture3, NULL, NULL );
SDL_RenderCopy( gRenderer, gTexture4, NULL, NULL );
//Update screen
SDL_RenderPresent( gRenderer );}
as you can see in the above CODE the SDL_RenderCopy uses the SAME renderer for RENDERING different TEXTURES. so what you need, is, many textures.
I'm certain there might be a use for multiple renderers but I have no idea why you would do that?
//the next day// So I checked this out, and Saw that if you have a Multiple Window Application you Can use Multiple renderers.
来源:https://stackoverflow.com/questions/21792146/sdl2-multiple-renderers