#1
  1. The Basketball Star
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2001
    Location
    H-Town
    Posts
    550
    Rep Power
    14

    Trouble making Graphics-based game


    I'm new to C#, and so far it's been going pretty well, but I've run into a problem. I'm trying to port my console-based C++ Graphical Pac Man game to a C# Windows application and I'm having a little trouble with the graphics.

    The game starts off with a simple graphical introduction and I've gotten it to work, but weird things happen. Sometimes it just goes in a continuous loop and starts eating up my memory and I have to use Ctrl+Alt+Del to close it.

    Maybe looking at some of my code will reveal my problem:
    Code:
    static void Main() {
      Application.Run(new SuperPac());
    }
    
    protected override void OnPaint(PaintEventArgs e) {
      Graphics pac = e.Graphics;
    
      Intro(pac);
      Thread.Sleep(2000);
      CheckFile();
      continueGame = MainMenu(pac);
     }
    So basically i'm trying to run my program through the OnPaint event, and I don't know if that's the cause of my error. I tried to do it through the PageLoad and then instantiate a Graphics object, but nothing would draw on the screen. This is the only way so far that I've gotten it to work, but I have a feeling that I'm not doing it correctly. This is all enclosed in a Windows Form by the way. I'm creating it in Visual Studio .NET so it created all that stuff for me.

    I'm also having a problem with my program quitting. The program doesn't seem to end after MainMenu is completed (there's actually nothing in there).

    I don't know if I should include more of my source code because I don't know how common this error is, but I have attached the two files that I'm using (main faile and class file).

    Thanks for all the help!
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo