Question

I'm creating a XAML Monogame and I want to set fixed play area in SwapChainBackgroundPanel. I mean, imagine: game screen (ex. 1920x1080), and game area (ex. 1280x800) is only a part of this, and other space is for diffrenet information like score, level, experience, etc., also different buttons, like in this picture:

screen example

Was it helpful?

Solution

You can set multiple render targets to draw to for your sprite batch. I would make your entire gameplay logic or area be drawn as or return a Texture2D at the desired size. Then in your Game1.cs or where ever, you position that texture accordingly in additional to the UI elements you draw.

public override Texture2D Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.GraphicsDevice.SetRenderTarget(gameRenderTarget);
        spriteBatch.Begin(SpriteSortMode.FrontToBack, null);
        sky.Draw(spriteBatch);
        ground.Draw(spriteBatch);
        background.Draw(spriteBatch);
        player.Draw(spriteBatch);
        spriteBatch.End();

        return (Texture2D)finalRenderTarget;
    }

Now that entire gameplay area is a texture to be manipulated just like everything else in your game! Your main game can predefine the game's layout and you just render each area as needed.

The other option is one Draw call you setup multiple render targets and just pass the previous render target to be drawn in the next spriteBatch.Draw call between spriteBatch.Begin() and spriteBatch.End().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top