XNA 4.0 reading an XML file

Started by
-1 comments, last by ProjectOlle 12 years, 11 months ago
Hey guys,

I need to read an XML file in XNA 4.0.

What Im doing is I am trying to make a Kinect game in XNA. As drivers I use these http://www.studentgu...y-tracking.aspx Which are pretty simple, and very useful.. However, in order to track a skeleton you need the method Nuitracker (Documentation new Nuitracker(string configuration)), this string configuration is meant to be a XML file. I got the file and all, and first I tried just adding it to the content and loading it by saying new NuiTracker("SampleConfig.XML") That did not work, It complained that it was the wrong format, so in the XML file I added <XnaContent>. Then it complained about assets, So I found a post that said i needed to include this in the file

<Asset Type="Namespace.className"> Then I added that, and it gives me the Error: "There was an error while deserializing intermediate XML. Cannot find type "KinectTest.Game1"

My namespace should be KinectTest, and the class name is the default one when creating a project Game1.

Im not even sure what this error really means, please any help here? I need this badly and urgent for a project.!!

Thanks in advance guys!

Here is the full test code (Its VEEEERY basic ;))


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Nui.Vision;

namespace KinectTest
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

NuiUserTracker _skeleton;
Vector3 cameraPosition;

Matrix ViewMatrix;
Matrix ProjectionMatrix;
float aspectRatio;
Model test;

float headX;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";

}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{

// TODO: Add your initialization logic here
cameraPosition = new Vector3(250.0f, 100.0f, 0.0f);

aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;

ViewMatrix = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.Up);
ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), aspectRatio, 10.0f, 10000.0f);

base.Initialize();

}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);


test = Content.Load<Model>("testSquare");

// TODO: use this.Content to load your game content here
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

_skeleton = new NuiUserTracker("SamplesConfig.xml");
_skeleton.UsersUpdated += new NuiUserTracker.UserListUpdatedHandler(Skeleton_UsersUpdated);
// TODO: Add your update logic here


base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here
foreach (ModelMesh mesh in test.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = Matrix.Identity * Matrix.CreateTranslation(new Vector3(0, headX, 0));
effect.EnableDefaultLighting();
effect.View = ViewMatrix;
effect.Projection = ProjectionMatrix;
}
mesh.Draw();
}

base.Draw(gameTime);
}
public void Skeleton_UsersUpdated(object sender, NuiUserListEventArgs e)
{

foreach (var user in e.Users)
{

#region Get body parts coordinates

float headX = user.Head.X;
float headY = user.Head.Y;
float headZ = user.Head.Z;

float neckX = user.Neck.X;
float neckY = user.Neck.Y;

float leftShoulderX = user.LeftShoulder.X;
float leftShoulderY = user.LeftShoulder.Y;

float leftElbowX = user.LeftElbow.X;
float leftElbowY = user.LeftElbow.Y;

float leftHandX = user.LeftHand.X;
float leftHandY = user.LeftHand.Y;

float rightSholuderX = user.RightShoulder.X;
float rightShoulderY = user.RightShoulder.Y;

float rightElbowX = user.RightElbow.X;
float rightElbowY = user.RightElbow.Y;

float rightHandX = user.RightHand.X;
float rightHandY = user.RightHand.Y;

float waistX = user.Torso.X;
float waistY = user.Torso.Y;

float leftHipX = user.LeftHip.X;
float leftHipY = user.LeftHip.Y;

float leftKneeX = user.LeftKnee.X;
float leftKneeY = user.LeftKnee.Y;

float leftFootX = user.LeftFoot.X;
float leftFootY = user.LeftFoot.Y;

float rightHipX = user.RightHip.X;
float rightHipY = user.RightHip.Y;

float rightKneeX = user.RightKnee.X;
float rightKneeY = user.RightKnee.Y;

float rightFootX = user.RightFoot.X;
float rightFootY = user.RightFoot.Y;

#endregion


}
}
}
}




and the XML file


<XnaContent>
<Asset Type="KinectTest.Game1">
<OpenNI>
<Licenses>
<!-- Add licenses here
<License vendor="vendor" key="key"/>
-->
</Licenses>
<Log writeToConsole="false" writeToFile="false">
<!-- 0 - Verbose, 1 - Info, 2 - Warning, 3 - Error (default) -->
<LogLevel value="3"/>
<Masks>
<Mask name="ALL" on="true"/>
</Masks>
<Dumps>
</Dumps>
</Log>
<ProductionNodes>
<Node type="Depth" name="Depth1">
<Configuration>
<Mirror on="true"/>
</Configuration>
</Node>
<Node type="Image" name="Image1" stopOnError="false">
<Configuration>
<Mirror on="true"/>
</Configuration>
</Node>
<!--
<Node type="Audio" name="Audio1"/>
-->
</ProductionNodes>
</OpenNI>
</Asset>
</XnaContent>

This topic is closed to new replies.

Advertisement