Home

Awesome

FNA Template

FNA Template is a simple, cross-platform way to start new projects using FNA (http://fna-xna.github.io/), Ethan Lee's excellent reimplementation of Microsoft XNA Game Studio.

Demonstration Video

It has been tested with Visual Studio 2010 (on Windows) and Visual Studio Community 2017 (on macOS), and should work with other versions of Visual Studio, MonoDevelop, or directly with MSBuild.

It uses MonoGame's content pipeline for building assets (except shaders), but does not use MonoGame at runtime. It does NOT require XNA or XNA Game Studio.

FNA Template is released under the Microsoft Public License. The contents of the "FNATemplate" directory, excluding the Roboto font, are additionally placed in the public domain and licenced under CC0.

Getting Started

To use FNA Template you will need to install the following:

At this point you should be able to open and build the solution. On Windows you can now run and debug the FNATemplate project. On Linux/macOS there is an additional step to run it in the debugger (instructions below).

(Linux/macOS) Installing the DirectX SDK on Wine

On Linux and macOS, the DirectX SDK is still required to compile shaders. On these platforms we use Wine to run the DirectX SDK tools.

To install Wine and winetricks on Linux, refer to your distribution's package database. Typically the package names will simply be wine and winetricks.

To install Wine and winetricks on macOS:

Once Wine and winetricks are installed:

NOTE: Ensure you have the latest version of winetricks, or you may hit this bug: https://github.com/Winetricks/winetricks/issues/841.

Alternative method: Instead of installing the DirectX SDK, you can place a copy of fxc.exe from the DirectX SDK in the build/tools directory. Then use winetricks d3dcompiler_43 to install the required DLL from the DirectX redistributable (this is a smaller download than the SDK). See BuildShaders.targets for details. The same fallback also works on Windows.

(Linux/macOS) Setting the library path for debugging

In order to run in the debugger on Visual Studio for Mac or MonoDevelop, you will need to add an environment variable:

On macOS, set the following environment variable:

On Linux, set one of the following:

You will need to repeat these steps for any new projects you create from the template (because they are per-user debugging settings, not part of the project file).

If the template crashes inside FNA with a DllNotFoundException, possibly as the inner exception of a TypeInitializationException, you forgot this step!

Using the CreateTemplate tool

Use the CreateTemplate tool to create new versions of the FNATemplate project (NOTE: Including any local modifications). This is easier than copying the files and fixing up names and GUIDs by hand.

The command line is:

CreateTemplate [--source <SourceDir>] [--solution] [--template] <ProjectName> <DestinationDir>

You can use it to directly create new projects (or an entire solution with --solution):

CreateTemplate NewProject "X:\yourSolution"

Creating a Visual Studio template

You can create a template for Visual Studio, which itself can be used to create projects.

CreateTemplate --template FNATemplate "X:\outputPath"

To install the generated template in Visual Studio:

(NOTE: Ensure that the .vstemplate file is at the root of the resulting .zip file. Otherwise the template will not work.)

Modifying an existing solution

If you have an existing solution and you would like to add FNA Template-derived projects to it:

Dealing with Content

Building and loading shaders

FNA Template uses fxc.exe (from the DirectX SDK) to build shaders, rather than using a content pipleine. This produces raw .fxb files rather than the usual .xnb content files.

To add .fx (shader source) files to your project: Add them and then set their Build Action to "Compile Shader" in the Properties window (typically the F4 key). (Set "Copy to Output Directory" to "Do not copy".)

To load a shader, read it directly from the .fxb file. For example:

myEffect = new Effect(GraphicsDevice, File.ReadAllBytes(@"Effects/MyEffect.fxb"));

An example shader is included in FNATemplate.

Note that if you are not creating your own shaders, you can safely delete the shader file and associated code from the template, and skip installing the DirectX SDK.

Building and loading other content

Other content is built using the MonoGame Content Pipeline. The .mgcb file in the template can be opened with the MonoGame Content Pipeline Tool.

Unlike MonoGame, simply create the content for the Windows platform.

Load content the same as you would with XNA or MonoGame. For example:

font = Content.Load<SpriteFont>("Font");

Runtime Asset Rebuild

A simple content rebuild system is included in FNA Template. To use it, press F5 while running a Debug build of the game. This will rebuild any modified content, and then call UnloadContent followed by LoadContent.

On non-Windows platforms, it requires that msbuild is in your PATH.

If you wish to use this in builds other than Debug builds, remove the relevant #if DEBUGs from the source code, and remove Condition="'$(Configuration)' == 'Debug'" from build/ContentRebuilder.targets.

Distributing your game

Please refer to https://github.com/FNA-XNA/FNA/wiki/3:-Distributing-FNA-Games