Click here to Skip to main content
15,443,549 members
Articles / Game Development
Posted 13 Sep 2010

Tagged as


12 bookmarked

XNA Game Engine Sample

Rate me:
Please Sign up or sign in to vote.
4.67/5 (4 votes)
19 Sep 2010CPOL5 min read
XNA game engine sample C# XBOX ANIMATION PHYSICS Skinned model loading particles


Unfortunately, the game code was hastily stripped and in poor condition, however it is still useful in many ways.  I will be trying to write a full tutorial on games for beginners over the next few  years.

At This State, Who is This Useful For

This is for beginners to steal the bits they need that are missing in XNA. It should be a great help for beginners to intermediate XNA programmers, especially the animation bits / how to load other animated models. It contains an upgrades ms skinning model sample. The math library also has many high level functions that are easy to understand such as rotating an object to face another in 2D or 3D, as well as position a 2D object with 3D coordinates, get a selected poly from a mesh, etc.

Background of the Engine and XNA

Everything is fairly optimized for XBOX which will be useful for many people. When I wrote this, I barely understood anything about 3D math and I am still no expert, but the good thing about that is I have encapsulated things so that you don't need to know much to do trivial tasks. When you start off in XNA, your expectations are so high, then you learn that the toolkit is not really going to produce quake 5 even in the hands of Carmack or anyone. Not only that, XNA IS* very unoptimized and not that* high level which is not what I expected at all. XNA is not a game engine, you have to create your own or use another one. Game engines are a bit of a catch 22; If you don't understand how to write one yourself, you will likely get stuck trying to do some trivial task. You can't even load an animated model (currently).

With this engine, you have a GameObject and GameObject3D that has a few main things such as Position and Destination, speed and gravity as you would kind of expect. You can use it to produce a 2D image or a 3D object with animation as you would expect XNA to do out of the box. You can also do operations such as get the 2D x,y of a 3D object with the mathHelper toolkit. The mathHelper contains almost everything you need to build a very simple game. (Note: Unfortunately, the Camera is very poorly written but you can easily grab another camera class off the net and plug it in. I say it is bad because it is currently hardcoded for viewing a level top down, it works, it is just specialized for the game I designed it for. I will be updating it soon.)


The 2D part uses textured quads not spriteBatch. This is because the gameobject has a layers property as you would expect!. GameObject3D also contains the layers property so you can intermingle 2D and 3D to your hearts' content and not be ripping out your hair!

Easily move objects by using destination property, and catch events like OnClick, OnCollision.

ParticleEffects XML editor scripts gameobjects to spawn with SimpleEmitter (f4) reloads changes in gameplay so you can edit them on the fly.

The engine runs pretty damn decent, it is not going to shatter any records but for the hobbiest it can get you by on XBOX game which is actually saying a lot from my experience with XBOX. Many structs are passed by ref which gives you a massive boost as well as the update is Not called when Isalive == false. The objects move in and out of a hashTable when isAlive == false. This allows you to have nearly unlimited amounts of objects lying around that are not being used. It uses heavy OO structure which lags xbox quite a bit due to the amount of overrides but it is easier to use so that is more important than performance. Windows blazes of course.

Animated models work. I am not up to date on all the new goodies in XNA, but in my day that was saying a TON!.

Basic Usage

If you look at player1.cs:

public override void Update(GameTime time)
float f = 3;
Destination3D = Levels.Inst.CurrentLevel.FindPos( GameMouse.inst.LClick() ,ref f);

Game objects can be an image or a static model or you can use animatedGameObject derived from gameObject3D to have an animated object.

This shows code above how to move and object by setting its destination. All game objects are derived from gameobject and exist in a collection gameobjects. The game objects are inserted into the collection automatically.

You can override many methods to gain access to events such as collision / mouse actions.

Particle effects are made from a collection of game objects. You can configure these collections in XML with the particle project. The coin stars are produced with this method for example. You will need to be intimately familiar with the engine to use the Particle effects. If you understand what every property of the gameobject does, you can use the effect XML generator because all the generator does is load the object in a property grid and spew them out with a few additional options.


Particle effects in game sample:

Old version 2009 game sample:

Funky Bits

  • A lot of specialization still needs to be removed. This engine was written for a little Dream build play game called Zombie defence which I am still working on.
  • Not really any special support for special shaders.
  • GameObject3D is derived from GameObject. They are very similar, and in fact you could have a 3D object that has an image attached to it but would not be super useful. It's a bit of a flaw in regards to the confusion between 2D and 3D functions. Just look out to use the 3D properties rather than the 2D ones in GameObject3D, i.e., position3D*.
  • Level class has no special culling abilities, it draws the whole sucker. This means your level cannot be massive. For my simple games, it works fine even with fairly detailed levels.

    GODependant object stores all dependancies of the engine. Dependencies will be cleared up when I move it to a DLL eventually.

  • 3D Sound is hacky atm.
  • You will see a bunch of static variables above methods. They increase the performance on xbox. Use slimtune to profile your games and understand passing by value or reference and don't instantiate needlessly. 



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

General[My vote of 2] Too soon Pin
Richard MacCutchan8-Sep-10 23:50
mveRichard MacCutchan8-Sep-10 23:50 
GeneralRe: [My vote of 2] Too soon Pin
rj459-Sep-10 5:32
Memberrj459-Sep-10 5:32 
GeneralRe: [My vote of 2] Too soon Pin
Richard MacCutchan9-Sep-10 5:56
mveRichard MacCutchan9-Sep-10 5:56 
GeneralRe: [My vote of 2] Too soon Pin
rj459-Sep-10 10:13
Memberrj459-Sep-10 10:13 
GeneralRe: [My vote of 2] Too soon Pin
Richard MacCutchan9-Sep-10 10:24
mveRichard MacCutchan9-Sep-10 10:24 
GeneralRe: [My vote of 2] Too soon Pin
RugbyLeague13-Sep-10 11:25
MemberRugbyLeague13-Sep-10 11:25 
GeneralRe: [My vote of 2] Too soon Pin
Richard MacCutchan13-Sep-10 21:23
mveRichard MacCutchan13-Sep-10 21:23 
GeneralRe: [My vote of 2] Too soon Pin
merlin98114-Sep-10 1:53
professionalmerlin98114-Sep-10 1:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.