Scrollbars for Strategy\War Game


I have been studying the MonoGame engine and have been successful in generating a tiled hexagonal map for the basis of a strategy\war game I would like to build. However, in such games the horizontal and vertical sizes of the game board\screen are often larger than the physical windows’ screen. How then does one go about adding scrollbars to the MonoGame screen so that a game screen can be scrolled horizontally and vertically by the user?

Thank you…

You have two separate problems to solve here

  1. Move around the map. You can do this by just displacing everything by a vector or passing a matrix to spriteBatch.Begin (if you’re drawing with a spritebatch).

  2. Register player interaction with the scrollbar. I assume you want to let the player use the mouse. You’ll have to register mouse down on the scrollbars and keep a variable that holds where the mouse was clicked down so you can check the difference in position until the mouse button is released. There are many tutorials on handling mouse input around, it shouldn’t be hard to find any in case you’re unfamiliar with it. If you like to use listeners instead of the explicit check for input, MonoGame.Extended has some stuff for that :slightly_smiling:

Then just use the value of the scrollbars as the displacement of the map!

If I understand, you’re looking for a camera.

And perhaps not as relevant:

Question I have is more related to the screen / game design - why use scroll bars to scroll the map, these days you don’t see that sort of thing on games. Alternative scrolling might be an option for you.

  1. If full screen - scroll when the mouse is at the edge of the screen - you can detect the mouse X,Y location and if X< 5 pixels scroll map right if X> screenwidth-5 then scroll map left - this is probably better for the user as gamers would be more use to this. You can even do this even if not full screen but its more of a pain for the user… :wink:

or 2 - use the cursor keys / wasd keys to scroll the map, so when the user presses the right cursor the map scrolls left.

If you need to use scroll bars, then you would have to “draw” these on the screen and then detect mouse position on the < > arrows as well as mouse clicked.

@Icecream-burglar & @Harag. Thank you for your very helpful information. I am going to take a more in-depth look at it today. I did suspect that what I was looking for was the use of the camera but since I am rather new at this type of programming I was probably not entering the correct search information when I was doing my research. Thank you, again… :slightly_smiling: