Multiple Consoles
v3 Tutorials
Goal
In this tutorial we’ll create sub consoles for each part of our game window and Blit them to the root console.
Sub Consoles
Our game is more than a map. It will also have areas for the inventory, player statistics, and a message log. We could just draw all these directly to the root console but it will be better to draw each to their own console and Blit them to the root in their correct positions.
Defining Console Dimensions
First we need to define the width and height of each of our sub-consoles and declare each RLConsole. At the top of Game.cs add the following code:
Instantiate the Consoles
Now we need to new up our four consoles with the widths and heights that we defined. In our Main() just after the line where we make a new RLRootConsole add the following code:
Set Background Color and Label
Next we’ll want to set the background color of each console and put a label on them so that we can verify that they are in the correct positions when we Blit them to the Root console. In OnRootConsoleUpdate() replace _rootConsole.Print( 10, 10, “It worked!”, RLColor.White ); with the following code:
Blit and Render
The final step we’ll need to take is to update OnRootConsoleRender() to Blit each of our consoles to the root console in the correct positions. The RLNET method we will use is RLConsole.Blit which takes several parameters.
A source console
- The X and Y position of the top left corner of a rectangular area from the source
- The width and height of the rectangular area from the source that we will be Blitting
- A destination console to Blit to
- The X and Y position of the top left corner of where we will Blit to in the destination console
And that’s it! If you run the program now you should see output similar to the screenshot at the beginning of this post.
Complete code for this post – https://bitbucket.org/FaronBracy/roguesharpv3tutorial/commits/tag/01SetupConsoles
Closing thoughts
So far we haven’t used RogueSharp at all. I think it is necessary to do some of these basic setup tasks to pave the way for the future. Don’t worry though we’ll be getting into RogueSharp functionality shortly.