Tuesday, August 31, 2010

How to: Remove the Game1.cs file

First off, sorry for the absence of posts. I don't really have an excuse other then I didn't know what to post about. Anyway, I have a few quick tutorials on using xna that might help. Now lets begin with the first one. Now when you create your game it comes with a few things and two of those items are a Game1.cs and a program.cs which I have never liked. Now if you were to delete the Game1 and just create a new class that does the same stuff as Game1 your game will not work and that is because of whats in the program.cs file. Now if you have done any console programming for c# you will easily recognize the code block within the program.cs class ( if you have programmed in c++ it is equivalent to the "int main" code block ) . The code block itself is just were the program will start when you execute it and it just says to run your game that it has conveniently named Game1. So all we need to do is change that to our new game that we will create. So lets begin by creating that new game class. So add a new class and name it whatever you want your base game class that I will call Base Game. Just like in Game1 we want to inherit the Xna framework game class and you can add all the variables you want here.
For shortness I deleted all the comments and collapsed all the functions and deleted the unload method but there all the same as Game1.