shawn's blog

As I have been developing in XNA I am constantly finding myself wanting to perform a task at a given interval or delay the performance of a task for a given period of time. Normally when I did this I had to simply create a float variable to store the elapsed time and once that variable got to my desired delay I executed my action. While this method is simple and straight forward it gets time consuming and over complicates code for such a simple action which I use many places in my application.

After a while of manually timing all of my tasks I decided that it was time to do something about it. This is where my TaskScheduler class comes in. This class is extremely simple and straight forward; it doesn't do anything fancy all it does is give me a way to extend my Game class with a little extra functionality.

I can schedule a task quickly and easily using the following syntax:

this.ParentModule.TaskScheduler.ScheduleTask(2.0f, MyEvent);

My implementation of this can easily be combined into a service to fit into the standard XNA implementation; my engine does not use the standard XNA structure so this is why I made it a stand alone class.

Download Source: TaskScheduler

I have been getting more and more emails with questions regarding tips/suggestions involving the creation of an XNA engine and editor; I have copied by response to one such email below to hopefully help answer some of the questions flying around out there.

The initial step to creating my 3D system was to think about what functionality I wanted in the editor; which to me the most important was something that you could easily add different games systems just like you would add components in VS, which is dragging and dropping the component into your scene. Since I had an idea of the basic functionality I wanted I knew that when developing my engine I wanted to make my engine as modular as possible and with that in mind I began development. Now in the editor I did not want to be updating the interface constantly as I was adding components to the engine so I used reflection for listing and creating the components available in the engine in the WinForms interface; this turned out to work amazingly well.

Some hints for making your project reflection friendly:

  • Put all your scene components in the same custom namespace; this way you can easily reflect that namespace to get a list of the components which you want available in your editor.
  • Make all your scene components have the same constructor; this way you always know what parameters your scene component will be expecting; a good way I found to make this possible is simply have a “resources” class which holds references for all the resources your components could ever need (ie graphics device, base game, etc…) and pass that in the constructor; that way each component can pick and choose what it needs to use.
  • When designing your components keep in mind that if you want to use existing WinForms components such as PropertyGridView component you need to properly expose the properties you would like visible through those controls (ie public).

One of the things that I spent the most amount of time on and I am still not nearly finished with is the materials system; this is something that I wanted easily editable and very expandable by the end user. The current system works very well for creating and editing materials but it offers no functionality for changing the materials on the fly on the models (although it could be easily expanded in the future to do this). The reason I bring up the rendering system is because depending on how you structure this system it could be crucial to how you structure your other game systems; getting a good rendering system down to start with will make things easier for you since you will know the parameters to work with when creating your other game systems.

Finally I found that making any “information” class serializable was very good practice for the long run because it enabled me to easily save out scene state information into a “Level” file which was easily deserialized later to get the same level; and with the information released on Shawn Hargreaves blog you could easily setup your classes so when you serialize them all important information is saved and this will simplify things for you a great deal in the long run.

One thing I have noticed when working in XNA is that the good old System.Drawing.RectangleF did not make it into the Microsoft.XNA.Framework! Now this has not been a big deal for most of my projects but I recently find myself moving objects and updating their "Bounding" rectangles to match; the only problem is the positions of the objects were stored in a Vector2 which means I have to do some ugly rounding and generate a new Rectangle each update. To solve this "issue" I implemented my own take on the RectangleF.

My RectangleF includes some methods which I use a lot and one that I put in just to test the concept and might confuse some of you; this function is the "ResizeToRotation" method. What this method does is rotate the points of the current RectangleF and then generates a new RectangleF which contains those points; it works very well for keeping a static AABR that tightly contains the OBR of an object.

Download Source: RectangleF

I have been working on the first installment of a new series of blogs I would like to do which covers the basics of creating your own 2D game engine. My goal was to create a series of tutorials that beginners and advanced programmers alike could enjoy and gain some knowledge from.

I approached this first article a little strangely; I wanted to develop the engine and then write the documentation to go with it. I think all and all the tutorial went fairly well but it does get a little hard to follow if you are trying to create your own project instead of just referencing the sample project.

My next tutorials will be a continuation of the sample code included with this tutorial and I will attempt to follow a more standard approach for those tutorials by writing my documentation as I develop and make changes to the code via notations in the documentation to get the reader more involved and give them an easier way to follow along in their own project. My next series of tutorials will focus on specific game systems and go a little more in-depth on each one individually; these game systems include Collision, AI, Particle Systems, and much more.

This Tutorial Covers:
- Introdocution to XNA GSE
- Creation of basic game components
- Using the Sprite Batch for drawing
- Creating an Input Manager to handle input
- Creating a basic ship class
- Creating a projectile management component
- Creating a star field background component

Download Tutorial: Source and Documentation

I implemented Andrew's Algorithm for creating convex hulls into an easy to use singleton class for XNA. All you need to do is simply use one of the GenerateConvexHull override methods and it will return a Vector2[] array which describes the convex hull in a clockwise direction.

I have not gone back through and optomized the class yet but I will be doing that soon; be sure to let me know what you think!

Download Source: XNA Convex Hull Generator

I was messing around with some physics and collision on sprites and I found that not only is using Per-Pixel collision detection expensive but it is also very hard to get accurate physics. After spending some time researching different types of 2D collision I found that 2D convex hull collision gave some of the best results and so I set to work on figuring out a way to get the best of both worlds; and that is where this Convex Hull Generator comes into play.

While reading through my Real Time Collision Detection book I found a reference to Andrew's Algorithm for generating convex hulls. After doing some quick searches through Google I found a great reference site and sample app here.

I spent some time converting the Java source code included in the sample app over to C#; the C# code works great for creating a point list from the pixels of an object and creating a Convex Hull from that information. I have included a download link to the source code and an easy to use Win Forms demo project below.

Download Source: Convex Hull Generator

Hey Guys! Sorry it has been so long since my last blog I have just been very busy at work on a couple game projects and moving my family to a new house!

Anyway, I am excited about this post; I have been working on a 3D engine and editor based in XNA and Windows Forms. The engine itself will run just fine on the Xbox 360; the editor obviously since it is based in Windows Forms will not. I have included some screen shots from the editor below.

A Few Features Include:
- Full 3D with basic physics and collision
- Full materials system, the editor contains a material editor.
- Drag and drop component functionality
- Foliage generation system taking advantage of shader instancing
- Fully shapeable and paintable terrain component
- Texture and Model viewers
- Model "Copy and Paste" function for quick duplicating models around a world
- Basic lighting system











Hey guys! This is a 2D engine I was working on a while back for a real time physics based artillery game which would have been loads of fun I think. The game actually has support for multiple controllers etc.. so you can play it with friends. It also has score tracking, post proccess effects, animated sprites, deformable terrain, and custom "pixel slides".

I will post my source code for download in the coming weeks; I want to wait until I have time to finish some of the systems I started and better comment the code. I would also like to write up a quick run down on how everything works and what my goals were for the systems.

Watch for the part where I am shooting the bouncing bombs... the air drop comes in and I nail the crate in mid air on a bounce! Now that is some accidental skill for you ;)

Hey guys thanks for checking out my blog! I have been working with XNA for about six months now and thought I might start giving back to the community which has helped me out so much.

Let me start by telling you a little bit about myself; I am an Oregon based Software Engineer and I work for a small Oregon based company. Like I said before I have been working with XNA for about half a year now and I am loving it! It has been my first major step into the world of game programming and it has been quite the experience.

I have worked on several game concepts and am currently working on a 3D game engine to power an XBLA game we are currently working on. I have an older 2D game engine which I worked on in the past which I will be posting more about shortly. I would like to use this blog to keep people up to date on what is going on the XNA community and also as a portal to begin releasing some of my XNA tutorials I have written; as well as the source code to various XNA games and systems I have written.

If you have any questions or comments please feel free to shoot me an e-mail shawnlehner@gmail.com