Just making a little game and want to layer my pause menu over top.
A timer is responsible for the game loop. When it's paused, it calls a separate function that draws the pause menu. Right now I am drawing a small centred rectangle. The rectangle however isn't transparent, even though I clear it to be transparent.
Is there any way I can do that?
Here's the code for my game loop that updates the states and draws based on them. As you can see, when the game is paused, it calls a separate method.
private void tmrGameLoop_Tick(object sender, EventArgs e)
{
if (Paused)
{
Pause();
return;
}
using (Graphics gr = CreateGraphics())
{
using (BufferedGraphicsContext bgc = new BufferedGraphicsContext())
{
using (BufferedGraphics bg = bgc.Allocate(gr, DisplayRectangle))
{
bg.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
bg.Graphics.Clear(Color.Transparent);
// draw the stuff
bg.Render();
}
}
}
}
This is Pause(). It draws over top as expected, but because it's a separate graphics object, it draws over and isn't transparent as I expected it to be.
private void Pause()
{
using (Graphics gr = CreateGraphics())
{
using (BufferedGraphicsContext bgc = new BufferedGraphicsContext())
{
using (BufferedGraphics bg = bgc.Allocate(gr, m_menu))
{
bg.Graphics.Clear(Color.Transparent);
// draw pause menu
bg.Render();
}
}
}
}
Is there any way to do this so that it is transparent?