1
\$\begingroup\$

I recently started building a simple 2D roguelike game using Monogame 3.4. I was keen on building the game "engine" myself as I saw it as a fun learning curve. Monogame was pretty much the best option for me to get started as I'm a C# dev by profession. After getting my sprite to run around on the screen, I figured I probably need a proper level to continue with the more interesting stuff. So I decided to build a level builder for the game.

I've been struggling and digging around tutorials regarding building a 2D Camera.

I used this camera tutorial and I preferred this specific implementation. My only problem is, currently, I have two Rectangles (Cameras) on my screen.

enter image description here

The Rectangle on the left represents a scrollable panel with all the available sprites but is also a sort of overlay. Underneath it, the level "map" is drawn. My question is simply, how would I enable my level Rectangle to scroll past the overlay to view the left-hand side of it, which is currently being obscured by the panel.

Relevant code files are here

I would appreciate all the help I can get. Thanks!

\$\endgroup\$
1
\$\begingroup\$

Managed to fix this by using Viewports when drawing the Rectangles / Cameras

        GraphicsDevice.Viewport = new Viewport(_level);

        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, _camera.ViewMatrix);
        DrawLevelTiles();
        spriteBatch.End();

        GraphicsDevice.Viewport = new Viewport(_panel);

        // draw panel
        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null, null);
        _spritePanel.Draw(spriteBatch);
        spriteBatch.End();

        // draw tiles to panel
        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, _panelCamera.ViewMatrix);
        DrawTiles();
        spriteBatch.End();
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy