Create a New XNA Game

Make sure you have properly installed Engine Nine 1.4 using the installer.

Open Visual Studio 2010. Choose File – New - Project in the main menu. Choose XNA Game Studio 4.0  – Engine Nine Game

image

 

Build and run the project, an empty plane will be shown. You can navigate around using WSAD and rotate the camera by dragging the right mouse button.

image

 

 

Prepare Game Contents

Drag and drop the asset files to WindowsGame1Content project.

Rename Scene1.xaml to MyScene.xaml.

 

 

Create a Scene using XAML

Open MyScene.xaml, clear all the existing content and replace it with the following XAML markups:

<Scene xmlns="http://schemas.microsoft.com/nine/2011/xaml">    
    <SkyBox Texture="{ContentReference Assets/Glacier}" />
    <AmbientLight AmbientLightColor="0.2, 0.2, 0.2" />
    <DirectionalLight DiffuseColor="0.8, 0.8, 0.8" Direction="-1, -1, -1" />
</Scene>

The root element of this XAML markup is a Scene. A scene in Engine Nine can contain arbitrary objects, including models, lights, physics colliders, sound effects, etc. Almost all the objects and components in Engine Nine can be directly added to the scene.

A SkyBox represents a cube mapped box model that will always move along with the current camera. To specify the appearance of the skybox, use ContentReference to refer to an external cube map content. The filename of the content reference uses relative path and it does not include file extension.

 

 

Load and Display a Scene

Open Game1.cs, add the following using statements at the top of the file:

using Nine;
using Nine.Components;
using Nine.Graphics;

Load the scene using ContentManager.Load method.

protected override void LoadContent()
{
    scene = Content.Load<Scene>("MyScene");
}

Update the loaded scene using Scene.Update method.

protected override void Update(GameTime gameTime)
{
    scene.Update(gameTime.ElapsedGameTime);
    base.Update(gameTime);
}

Draw the loaded scene using Scene.Draw method. This method takes a GraphicsDevice parameter to initialize any graphics data when necessary.

protected override void Draw(GameTime gameTime)
{
    scene.Draw(GraphicsDevice, gameTime.ElapsedGameTime);
    base.Draw(gameTime);
}

 

 

Add a 3D Model

Open MyScene.xaml. Just as skybox, adding a 3D model is also very easy and straightforward. The Model tag can be used to create a 3D model. Add the following XAML markup to the MyScene.xaml under the Scene element:

<Model Source="{ContentReference Assets/Tank}" Transform.Scale="0.05,0.05,0.05" Transform.Rotation="{Degrees 0,45,0}"/>

Again ContentReference is used to reference a model asset just like textures. Transform.Scale is an attached property to adjust the scale of the model. Transform.Rotation can be used to adjust the rotation of the model on three axis. The internal representation of rotations are using radius, use Degrees tag to convert from degrees to radius. Transform.Position can be used to adjust the position of the model, which is not demonstrated here.

Now press F5, a tank model will be shown at the center of the screen. A first person fre

e camera will be created by default. Move the camera by pressing W, S, A, D. Pressing Z, X to raise or lower the camera vertically. Hold down the mouse right button to change the view angle.

image

 

 

Manipulate the Scene using C#

Using XAML to represent a scene has a lot of advantages, it is compact and it is compiled as a content just like textures. However, there are times when XAML doesn’t have enough vocabulary to describe a dynamic game.

Using C# to create a scene is just as easy and using XAML. In fact, each XAML element and XAML property has a corresponding C# companion with the same name. The following code snippet shows how to add a 3D model in C#:

scene.Add(new Nine.Graphics.Model(GraphicsDevice) 
{
    Name = "MyTank",
    Source = Content.Load<Microsoft.Xna.Framework.Graphics.Model>("Assets/Tank"),
    Transform = Matrix.CreateScale(0.05f) * Matrix.CreateTranslation(-50f, 0, 0),
});

 

To find an object in the scene, use Scene.Find method. Add the following code in the update method to move the tank:

var tank = scene.FindName<Transformable>("MyTank");
tank.Transform *= Matrix.CreateTranslation(0, 0, 0.05f);

 

 

 

Add Post Processing Effect

This simple 3D game is almost done. Let’s add some HDR (High Dynamic Range) effect.

HDR effect requires HiDef graphics profile. Right click on WindowsGame1 – Properties, set the game profile to HiDef:
 
image

 

Then place an HighDynamicRangeEffect object inside the scene.

image

Download the source code here

Last edited Nov 28, 2012 at 7:03 AM by yufeih, version 30

Comments

bloodhound92 Jan 9, 2013 at 9:31 PM 
Also, I am using Visual Studio 2010 Express Edition. I hope this helps.

bloodhound92 Jan 9, 2013 at 2:20 PM 
I cannot access the Engine Nine Game template in Visual Studio. It is not listed under the templates in the XNA Game Studio 4.0 category. I installed the Engine Nine platform using the Engine.Nine.1.4 installer. I am running Visual Studio Express C# Edition. Please help. I love that this project is still being updated and how robust the possibilities are with this engine.

boblang99 Nov 26, 2012 at 4:42 PM 
5. You need to make clear that the scene.Add(...) code should be placed in the LoadContent() method of Game1.cs
6. Add a Post Processing Effect. You say "It can be either in XAML or in C#!" but don't actually tell us how to do it!

Sorry, if I've been somewhat critical, but let's say that getting this far has been extremely difficult. I think you make the basic developer mistake of assuming that the prospective user knows everything you know, and writing your documentation, worksheets, etc on that basis. If you hope to get this more widely used, then all stages from installation to getting a game running must be greatly simplified.
I'm seriously considering adopting Engine Nine as part of a game design teaching module, but given the problems I've had with it, I'm just not sure that the students will be able to cope with it. I've run into problems at almost every step of the way, and it really leaves a bad impression. I'm happy to talk more privately, and maybe offer some assistance. Bob

boblang99 Nov 26, 2012 at 4:22 PM 
1. I recommend you have a separate download for the assets, and this should go FIRST on the worksheet rather than being buried in the download at the end of the worksheet.
2. The only way I could get the References into the project(s) was to browse to the folder, and the one for System.xaml is hidden away in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xaml.dll
3. The scene variable in Game1 needs to be declared as a global field.
4. You need to tell the user to create a separate Assets folder in the content project, and then Add Existing files from your downloaded project into it.