Note: This section is not necessary if you started with tutorial #1 after 12/10/2008
I want to post a little update I’ve made to the engine that doesn’t really need to be a tutorial itself. You don’t need to do this, but I’ve found that it can help with debugging later on. The problem I ran into several times is that I forgot that the engine had to be initialized before we could make components. This means that doing something like
public class Game1 : Game
{
Actor actor = new Actor(...);
public Game1()
{
.... and so on
would crash, because the engine had not set up its list of components in LoadContent() yet, and so was not ready to take new components. So, to remind myself not to do this, I added an exception that would be thrown if a component tried to set itself up before the engine was ready.
So, first we add a boolean to the Engine class called “Initialized”:
// Whether the engine has been initialized with SetupEngine() public static bool IsInitialized = false;
Then set it to true at the end of the SetupEngine() method:
// Let components know the engine is ready to accept them IsInitialized = true;
Now in the InitializeComponent() method of the Component class, we will first check if the engine has been intitialized, and if not we throw an exception to remind ourselves of this. Add this to the beginning of that method:
// Check if the engine has been initialized before setting
// up the component, or the Engine will crash when the
// component tries to add itself to the list.
if (!Engine.IsInitialized)
throw new Exception("Engine must be initialized with "SetupEngine()""
+ "before components can be initialized");
Now, if we try to setup a component before the engine is ready, we will get a message telling us about it instead of a random crash. Note that something like this would still be fine:
public class Game1 : Game
{
Actor actor;
GraphicsDeviceManager graphics;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
}
protected override void LoadContent()
{
Engine.SetupEngine(graphics);
actor = new Actor(...);
}
... and so on
« XNA Game Engine Tutorial Series #5 – Physics New Forums Up »

Hello Sean, I have been following your tutorials and think they are great. I have a few ideas for expanding the engine and was just wondering if you are going to be writing more tutorials for the engine? I am going to first implement a input system.
Hi Sean. Maybe you could set up a forum so we can discuss modifying the engine.
I would be happy to set one up for you.
since you have experience with php and mysql you now how to do it yourself but if you don’t have enough time I’ll help.
I know you have set up the engine so it can have an input system so are you going to cover that soon or should I try and create one myself?
Yes, there will be more tutorials, and in fact the next one is on designing an input system.
Also, I’ve been thinking about setting up a forum. I think I’m going to use some WordPress plugin to do it. If not, I’ll use one of the free ones you can download and set up a database table for then have it do the rest.
well bbpress is light and integrates well with word press. But it isn’t even 1.0 yet. I’ve always liked phpbb mainly because it has a large user base and lots of customisations plus it think I can get phpbb and wordpress to do everything here http://bbpress.org/documentation/integration-with-wordpress/ since I have programmed with both. but its your choice and I guess if your hosting isn’t that great bbpress would be litter. plus who would actually use the integration of wordpress and bbpress anyway?
Ok I installed BBPress. It does integrate nicely, and you can share users between the forums and wordpress, and the admin stuff is very similar. Nice and simple, and easy to install.
Very nice. I’m using (and expanding) this engine for use in my upcoming 3D game.
One thing i want to point out is in the current state you can’t load models with meshes in different positions because if you do they all get set to the position you specify for the PhysicsActor. I modded the draw code to handle this (I might make a new type, well i should make a new type come to think of it, because a level really isnt a actor).
So now i have a level (was designed in 3D Studio Max) loading into the engine and a controllable camera (did simple input) and also created a neat function that does a flythrough of the level (you just pass it some positions and rotations and it moves the camera around to those positions in a (semi*)smooth manner)
* Choppy at times because i need to fix some of the math, but still doing decently OK.
If anyone is interested in how i did any of this feel free to ask on the forums Sean just setup because i will be checking there through out the days
Well.. I’m interested.. I’ve got Free-Look, Position-Target, and Arc-Ball cameras written, just haven’t put them into tutorials. And you’re right we need to be offsetting by the parent transforms on the model’s bones.. I’ll put that into another update when I release one for a few other things as well.
Well could you send me over those cameras for me to play around with? (I don’t really need the tutorials, i just want to play with the cameras)
You can email me at bob3695@gmail.com
What are you interested in? All of it? Email me and ill show you in email what i did to get to the point im at.
As a side note, I will be doing lots of upgrading/modifying of the engine as i am writing a game using it already so if you think of anything you want to test out on it feel free to ask me to because i already have almost a semi working game written using the engine.
If you want to read a reader’s feedback
, I rate this article for four from five. Detailed info, but I just have to go to that damn google to find the missed pieces. Thanks, anyway!
bbPress is so easy to use and to customize. Also, I recommend http://www.bbpressthemes.net for cool bbPress templates. ^^