What is more, you should also know that thanks to the integration of XNA GS with Visual Studio, in order to add a new component you just:
- Go to the solution Explorer,
- Browse the list of projects,
- Right click with you mouse over the selected project,
- Select Add -> New Item,
- Choose "Game Component" from the list of available components,
- Click the "Add" button, and
- Voilá ... your new game component file is included in the project.
This is great!
Now, and again: if you've been using the XNA Framework you should know that there is a specification of the game component class for those that will be drawed to the screen: "DrawableGameComponents".
Unfortunately, if you want to create one of those components there's no shortcut, meaning either you create it by scratch or use a game component file as your source file and then modify it accordingly. In short, there is no DGC template integrated into VS, yet.
To change this, however, you could just create your own DrawableGameComponent template by going in VS to "File -> Export Tamplate", and then choosing the item you want export as a template.
After following the whole exporting process you can get and also integrate your new template to the list of items that you can pick when using VS "Add New Item" feature.
The problem with this solution is that your new template will be listed by default under the "My Templates" section of the "Add" dialog control, completely unrelated to the "XNA Game Studio 3.0" items section. Maybe you're fine with this solution generated "by default", but if you don't, then you have to tweak a little your recently generated template, change its location and one more thing that I will explain in what follows.
First, I have uploaded a class template for the drawable-game component here:
This template contains all the proper files that will helps us to better integrate it into VS.
Thus, follow whis steps:
- Download the above-mentioned template .zip file,
- Optional: open the .vstemplate file to find how the trick works,
- Search for the "ItemTemplates" folder in the directory where your Visual Studio 2008 version is installed, and
- Copy the .zip file into that folder.
Usually, the "ItemTemplates" folder is located in "%vs90comntools%\Common7\IDE", so say if you're using VS08 Standard, Pro or Team edition, you'd probaly find something like "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates".
We are almost done, now. There is just one more little procedure we must follow before reaching our goal:
- Go to Start -> Microsoft Visual Studio 2008 -> Tools,
- Open "Visual Studio 2008 Command Prompt" as an Administrator,
- Execute the following self-explanatory command "devenv /installvstemplates".
- When the command finishes, (re)open Visual Studio.
In case you're using the express version you have to browse for the folder in the start menu for that edition and, instead of typing "devenv" as stated in (3.) above you must type "VCSExpress".
If everyhing goes ok, everytime you want to add a new item template you should see something like:Or better yet:By the way, you can use your own icon design if you don't like the one I provided in within the zip. To replace it, just delete the "old" one and include your own in the zip file, respecting the old name (that is, the name requested by the template XML file).
Well, that's pretty much it. I hope you find this useful. And yes, you can repeat this same procedure for every item template you want to include under the "XNA Game Studio 3.0" items section.