Getting Started

There are only 3 easy copy-paste steps you need to use to create a Class with all the XNA functionality you need inside your WPF application.

Step 1:

Change your Game Class' declaration from

public class Game1 : Microsoft.Xna.Framework.Game {
/* ... */
}

to

public class Game1 : Xnaml.Game {
/* ... */
}

Step 2:

Make sure you're using the Xnaml.GraphicsDeviceManager or a derived version of it.

Microsoft.Xna.Framework.GraphicsDeviceManager graphics;

to

Xnaml.GraphicsDeviceManager graphics;


Step 3:

Make sure your game doesn't try to start (and resultingly crash) when you're using WPF/XAML's GUI Editor in Visual Studio by doing all your constructor intialization when the Application isn't in Design Mode:
public Game1 ( ) {
	// When working in WPF, XAML will try to instantiate an instance of
	// the class to do drawing with in the Editor.
	// Thus, a property - DesignTime -
	// will let you know if you're actually running your game
	// [ DesignTime = false ] or if it is just XAML trying to make a
	// class
	if ( !DesignTime ) {
		// The GraphicsDeviceManager was made to work exactly like Microsoft's,
		// so just call the constructor with the current game
		// like a regular Graphics Device
		graphics = new Xnaml.Graphics.GraphicsDeviceManager( this );
		// Content is identical
		Content.RootDirectory = "Content";
	}
	// After this, Everything is the same, expect with more features for
	// Interacting with WPF. See the overridden ReceiveMessage function below.
}

Last edited Apr 26, 2012 at 1:00 AM by ThePhD, version 2

Comments

No comments yet.