Varcade Dev Blog

Coding

Sprite Font Tools for MonoGame and XNA

by on Jul.01, 2013, under XNA

I’ve used both of these with MonoGame 3.0 projects.

The first was made to create bitmap fonts for the XNA 4.0 SpriteFont class, works with MonoGame, is easy to use, and has many effects.

Sprite Font 2SpriteFont 2

The 2nd one does not create native XNA SpriteFont compatible bitmaps, but supports unicode and generates an XML character map, giving it more flexibility. There is this C# BMFont XML Deserializer and a tutorial showing how to use it in MonoGame.

BMFontBMFont

3 Comments more...

Unlocking the framerate in XNA with Mango

by on Jul.31, 2011, under XNA

With Mango, developers have the option to run their XNA apps at the full refresh rate of the devices.  Previously, this was limited to every other frame.   Here is the code, in the Game class constructor:

graphics = new GraphicsDeviceManager(this);
graphics.PreparingDeviceSettings += (s, e) => { e.GraphicsDeviceInformation.PresentationParameters.PresentationInterval = PresentInterval.One; };

The default is PresentInterval.Two

Leave a Comment more...

MD2 Charater Animation for XNA

by on Jun.26, 2011, under Graphics, XNA

Skeletal animation has been the standard method for doing character animation in games for awhile.  XNA provides a GPU accelerated skinned model pipeline by default.  On WP7 phones, where using the CPU for the skinning can actually be faster,  a CPU Skinning pipeline is provided in the online samples library.

There are times when you don’t need the complexity of skeletal animation, when smoothly blending between multiple animations isn’t required.  Such as the case I had for doing a flock of 3D birds, where they have only a single ‘flap’ animation cycle, but it turned out useful for other objects or characters that have simple motion cycles.

So the best technique I found to save processing time was going back to the old school style of Quake animations, sometimes known as vertex blending, or morph targets.

The Tools:

MD2 Model Class: http://matthewlynch.net/xna/xna-md2-update/


The MD2 class above can handle the loading and animating of MD2 files.  It does not use the Content Pipeline.  You will want to put your MD2 files in the Content section of your project and set them to Build Action: None, and Copy to Output: Copy Always/Newer
I had a few issues with the class, and made some improvements

  1. It expected the frame names in the MD2 to be a specific format (name+number), to separate them into diferrent animation sequences.  Depending on how you are creating your MD2 files, you may need to play with frame names. I commented out that code and just had all frames of the walk cycle named WALK, next set of frames named RUN, etc. ( see other tools below for ways to rename your frames or combine animations if your exporter doesn’t )
  2. It loaded the raw normals information from the MD2, but did not use them.  If you want to do lighting in XNA, you will need normals.  Normals in the standard MD2 are stored as a byte index, which coresponds to a vector lookup table.  Being only 162 values in this lookup table, the normals are only an approximation of the true normal and are pretty rough.  I implemented the code needed to recreate the normals in XNA.  They give you what the format supports, but you may want to calculate proper normals yourself.
  3. It supported animation framerate ( playback rate ), but only increasing it. Now things can be slowed down as well. This has been moved to a Update(GameTime) function.
  4. There is no interpolation between frames. This works fine for many cases. The phone is only running at 30fps, and my animation in the MD2 is 30 frames per sec, so things look smooth. If you are targeting a 60fps platform, or want to be able to increase/decrease the animation speed dramatically, you might want to implement vertex interpolation. I would probably just store my animations in the MD2 at 60fps if that were the case, skipping the interpolation and trading memory for CPU time.

The original code was released under a Creative Commons License, so here is my version.

 

Q2 Modeller 0.91: http://en.wikipedia.org/wiki/Quake_2_Modeler (dropbox download)


An oldie but a goodie.  It can load/save md2 and several other formats, rename each frame, and combine multiple files into one ( walk cycle, death cycle, etc ).  I used it mostly to test the MD2’s I was creating, while I worked though problems in the MD2 XNA class.

 

Content Creation:


For content creation I was able to use the exact same skin and bones models I had already created for .FBX or .X formats, and just export to MD2 with no additional work required.  I use 3D Studio Max, and found a couple of ways to export to MD2. The first is a plugin called QTip. It’s $25 and the animation exported worked first try in XNA.  I also found some Maxscripts (export, export, import) that do about the same job.  These are 2 version of the same exporter here, 1.01 by the Adam Barton,  and 1.6  with some additions by JCA, plus some changes done by myself to work with the XNA class ( frame names ), and made so both scripts can be installed at the same time. ( put them in Scripts/Startup )

 

Mummy Walk

Mummy with Motion Captured Walk Cycle

 

Leave a Comment more...

XNA Drawing 2D Lines, Shapes, and Laser Beams

by on Feb.26, 2011, under Coding, Games, XNA

I’ve been using this great XNA lib for drawing 2D lines, circles, and shapes for awhile. I’m using an older version that I cleaned up to minimize garbage collection ( to none! ), but the code is still being updated by CentauriBoy on the AppHub forums, and recently got anti-aliasing and filled shapes added.

Home thread on XNA forums: http://forums.create.msdn.com/forums/t/7414.aspx

Download: BasicPrimitives.zip

Docs:  HOW_TO.txt

A simple example I use to draw a laser beam

beam = new BasicPrimitives(Game.GraphicsDevice);

beam.ClearVectors()
beam.AddVector( this.position ); // Vector2
beam.AddVector( target.position ); // Vector2
beam.Colour = new Color(255, 255, 255, 180);
beam.Thickness = 1;
beam.RenderPolygonPrimitive(spriteBatch);

Notice the color in this example is slightly transparent. For my laser beams, I’m stacking 3 to 5 of these lines with slight offsets to get a glow effect. Also note that using ‘new Color’ in a draw loop is bad practice. You never want to be creating anything in your loops because it will later need to be removed by the garbage collector. To eliminate garbage collection, you would define your colors once in a constructor, and re-use them.

1 Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...