[ANSWERED] Scrolling a Map Board with A RenderTarget ???

Thanks to Jjagg on this forum I have been able to update my game code successfully using his sample code as a base.

Now my map-board displays correctly. However, I have to rework my scrolling code.

This is where I am somewhat lost on how to go about this. I imagine that I have to select out that portion of the RenderTarget to which the user has just scrolled to. However, how does one go about this?

Thank you for any help provided…

:relaxed:

Are you just trying to replicate the Age of Empires mini-map?

Hi Mr. Valentine…

No. I have designed my own map-board based upon 72x72 hexagonal tiles. The base board will comprise of a width of 40 hexago9nal tiles and height of 200.

I believe my problem stems from not having enough knowledge regarding the SpriteBatch.Draw() method, which in some of its overloads will allow for the extraction of segments of a RenderTarget2d hidden map-board object. As a result, scrolling movement can be emulated by using the calculations in the Update() event (which I already have coded) to select out the position of a camera-view in the RenderTarget2D buffer\object.

:relaxed:

You could cheat the thing you know…

Simply drawing the map off a camera and drawing the camera to a render target…

Hope that makes sense, about to go to sleep :zzz:

I implemented this in the sample I provided. I don’t draw the whole render target, just the part that is visible. It also allows scrolling using the arrow keys. I use the SpriteBatch.Draw overload that takes a source rectangle which specifies what part of the drawn texture will be rendered to the destination rectangle.

Thank you again, guys…

I’ll have to take a look at your sample code again, Jjagg. I think I was concentrating too much on your mini-map so I probably overlooked what you are describing…

:relaxed:

Jjagg…

I found the area in your code that defines what I need to do. Thank you once again… :relaxed:

    private Rectangle SourceRect => new Rectangle(
        (int) (_offset.X),
        (int) (_offset.Y),
        (int) (GraphicsDevice.PresentationParameters.BackBufferWidth / _zoom),
        (int) (GraphicsDevice.PresentationParameters.BackBufferHeight / _zoom));

<<<

2 Likes