For some reason, this code does not actually draw my bitmap file… or show the form.
namespace GraphicsEngine
{
public partial class Form1 : Form
{
Bitmap[] dude = new Bitmap[3];
Bitmap dude0 = new Bitmap(@"C:\Directory.bmp");
Point renderpoint = new Point(1, 1);
public Form1()
{
dude[0] = new Bitmap(@"C:\Directory.bmp");
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MainLoop();
}
private void MainLoop()
{
double FPS = 30.0;
long ticks1 = 0;
long ticks2 = 0;
double interval = (double)Stopwatch.Frequency / FPS;
while (!this.IsDisposed)
{
ticks2 = Stopwatch.GetTimestamp();
if (ticks2 >= ticks1 + interval)
{
ticks1 = Stopwatch.GetTimestamp();
this.Invalidate();
}
Thread.Sleep(1);
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(dude0, renderpoint);
}
}
}
Any ideas?
Your problem ought to be a bit more obvious than not seeing the bitmap, you should not see the form either. That’s because you never complete the Load event. You could use the Shown event instead.
Check this thread for the code for a true game loop.