Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Pages: 1
Topic closed
answer:
public void InitializationCode()
{
Debug.WriteLine("\n");
Debug.WriteLine("InitializationCode() Activated");
int sizeW = GameFrame.Size.Width;
int sizeH = GameFrame.Size.Height;
Debug.WriteLine(sizeW.ToString() + "//" + sizeH.ToString());
Bitmap a = new Bitmap(sizeW, sizeH);
if (SetupGame.FillScreen)
{
for (int y = 0; y < a.Height; y++)
{
for (int x = 0; x < a.Width; x++)
{
a.SetPixel(x, y, SetupGame.FillScreenColor);
}
}
GUI = a;
GameFrame.Image = GUI;
}
}
Hello. I am trying to make a game template, mainly because I'm interested with Bitmap, PictureBox, and Graphics. I have the following code:
GUI = new Bitmap(GameFrame.Image.Width, GameFrame.Image.Width);
if (SetupGame.FillScreen)
{
Graphics g = Graphics.FromImage(GUI);
g.FillRectangle(new SolidBrush(SetupGame.FillScreenColor), new Rectangle(0, 0, GameFrame.Image.Width - 2, GameFrame.Image.Height - 2));
g.Save();
GUI = new Bitmap(GameFrame.Image.Width, GameFrame.Image.Width, g);
GameFrame.Image = GUI;
g.Dispose();
}
public static Bitmap GUI;
class SetupGame
{
/*
*
* Setup the game using these options
*
* Just modify them, the game will take place
*
* From [cencored my irl name], 9/24/2015 10:06 PM
*
*/
public static bool FillScreen = true;
public static Color FillScreenColor = Color.Red;
}
I cannot find out what's going on.
The current code as stated in the first code box doesn't draw a rectangle. The width and height of the GameFrame (Picturebox) is 484, 462
Offline
I don't feel particularly inclined to do all the steps required to properly debug your code
Personally I haven't ever created a new bitmap on top of one that I've already created.
Seems backwards.
I'm thinking your bug is due to the misspelling of the word "censor".
edit:
Ok, turns out I am motivated enough to humor this bug
And yes, it's what I thought it was.
Why do you even bother making GUI a larger-scope variable if you're going to completely pull a new bitmap every time?
Offline
Why do you even bother making GUI a larger-scope variable if you're going to completely pull a new bitmap every time?
This is the bigger scope
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Image_Game
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Bitmap GUI;
private void Form1_Load(object sender, EventArgs e)
{
GUI = new Bitmap(GameFrame.Image.Width, GameFrame.Image.Width);
if (SetupGame.FillScreen)
{
Graphics g = Graphics.FromImage(GUI);
g.FillRectangle(new SolidBrush(SetupGame.FillScreenColor), new Rectangle(0, 0, GameFrame.Image.Width - 2, GameFrame.Image.Height - 2));
g.Save();
GUI = new Bitmap(GameFrame.Image.Width, GameFrame.Image.Width, g);
GameFrame.Image = GUI;
g.Dispose();
}
}
}
}
Offline
You can't dispose GUI when it's loaded in the picturebox.
Offline
Offline
I tried removing "g.dispose()" and that did nothing. I now have this code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace Image_Game
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Bitmap GUI;
public void InitializationCode()
{
Debug.WriteLine("\n\n\n\n\n\n\n\n\n");
Debug.WriteLine("Form Loaded");
int sizeW = GameFrame.Size.Width;
int sizeH = GameFrame.Size.Height;
Debug.WriteLine(sizeW.ToString() + "//" + sizeH.ToString());
Bitmap a = new Bitmap(sizeW, sizeH);
if (SetupGame.FillScreen)
{
Graphics g = Graphics.FromImage(a);
g.FillRectangle(new SolidBrush(SetupGame.FillScreenColor), new Rectangle(0, 0, sizeW - 2, sizeH - 2));
a = new Bitmap(sizeW, sizeH, g);
GameFrame.Image = a;
GUI = a;
}
GameFrame.Refresh();
}
private void Form1_Load(object sender, EventArgs e)
{
InitializationCode();
}
private void MouseMoved(object sender, MouseEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
InitializationCode();
}
}
}
I am completely stumped.
Here's the debug data:
Form Loaded
484//462
Offline
But g.Dispose is the graphics, not the bitmap
What are you going on about?
you guys said i was disposing GUI, but I didn't see GUI.Dispose();
So I figured you were talking about the Graphics g.
If you are really talking about GUI, where did I dispose it?
EDIT:
I can't define the bitmap as a new bitmap with GameFrame.Size.Width or Height, So i have do define it at Form1_Load()
Offline
I never said "Dispose" but ofc.
I'm somewhat curious why the forums have let this little conversation take so long
The problem is rather plain as day, yet here we are, discussing it to no avail. I wonder how far we can push it?
Major hint: you aren't defining it once.
Offline
I never said "Dispose" but ofc.
I'm somewhat curious why the forums have let this little conversation take so long
The problem is rather plain as day, yet here we are, discussing it to no avail. I wonder how far we can push it?Major hint: you aren't defining it once.
I don't understand what you mean by I'm not defining it once. I'll ask on stack over flow
@mods: you can lock if you choose to.
Offline
Also. Remove "a = new Bitmap(sizeW, sizeH, g);" and everything should work.
I have no idea why you are using it two times.
Offline
Also. Remove "a = new Bitmap(sizeW, sizeH, g);" and everything should work.
I have no idea why you are using it two times.
I do it twice because I need to convert the new generated graphics into a bitmap
Offline
I have decided to simply do
public void InitializationCode()
{
Debug.WriteLine("\n");
Debug.WriteLine("InitializationCode() Activated");
int sizeW = GameFrame.Size.Width;
int sizeH = GameFrame.Size.Height;
Debug.WriteLine(sizeW.ToString() + "//" + sizeH.ToString());
Bitmap a = new Bitmap(sizeW, sizeH);
if (SetupGame.FillScreen)
{
for (int y = 0; y < a.Height; y++)
{
for (int x = 0; x < a.Width; x++)
{
a.SetPixel(x, y, SetupGame.FillScreenColor);
}
}
GUI = a;
GameFrame.Image = GUI;
}
}
It seems to be doing well and fast.
@mods: lock plz
Offline
Pages: 1
Topic closed
[ Started around 1732449101.8049 - Generated in 0.075 seconds, 13 queries executed - Memory usage: 1.54 MiB (Peak: 1.71 MiB) ]