<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GoGo-Robot &#187; xna</title>
	<atom:link href="http://www.gogo-robot.com/tag/xna/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gogo-robot.com</link>
	<description>Independent Games Developer</description>
	<lastBuildDate>Fri, 27 Jan 2012 11:18:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>XNA Skinned Model Animations</title>
		<link>http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/</link>
		<comments>http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/#comments</comments>
		<pubDate>Mon, 30 May 2011 15:36:33 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[skinning]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=379</guid>
		<description><![CDATA[The Skinned Model sample from the App Hub education catalogue is great for getting animated characters into your game, but there&#8217;s a bit of a flaw with the export process. The problem is, when you export your character from 3DS Max (and possibly other modelling programs), all you get is one animation, named &#8216;Take 001&#8242;. [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://create.msdn.com/en-US/education/catalog/sample/skinned_model">Skinned Model</a> sample from the App Hub education catalogue is great for getting animated characters into your game, but there&#8217;s a bit of a flaw with the export process. The problem is, when you export your character from 3DS Max (and possibly other modelling programs), all you get is one animation, named &#8216;Take 001&#8242;. Wouldn&#8217;t it be nice if we could define different animations for different parts of the animation timeline? Well, we&#8217;re going to do just that <img src='http://www.gogo-robot.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . As an added bonus, we&#8217;ll also be adding in events, so you can be notified when certain parts of your animation are hit.
<p><span id="more-379"></span></p>
<p>This tutorial is based on the Skinned Model sample, so grab it from the <a href="http://create.msdn.com/en-US/education/catalog/sample/skinned_model">App Hub</a> if you want to follow along, or skip to the end if you want the final version (which is released under the same license as the original).</p>
<p>What we&#8217;ll be doing is creating an XML file to go with our exported model, which will define our animation clips and events. The animations defined in this file will replace animations defined in the source model file. So, first thing is to define the class that will be represented by the XML file. Create a class in the SkinnedModelPipeline project named AnimationDefinition, like so:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content.Pipeline</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content.Pipeline.Serialization</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> SkinnedModelPipeline
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// A class for storing our animation definitions</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> AnimationDefinition
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The original clip name that was exported by the modelling package</span>
        <span style="color: #008080; font-style: italic;">/// Usually this will be Take 001</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> OriginalClipName
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The number of frames in the original animation</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> OriginalFrameCount
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// A class for storing information about individual clips that we want to create</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ClipPart
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The name we have given the clip</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> ClipName
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The starting frame of the clip</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> StartFrame
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The ending frame of the clip</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> EndFrame
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// A class for defining events in an animation</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #0600FF; font-weight: bold;">Event</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
                <span style="color: #008080; font-style: italic;">/// The name of the event</span>
                <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
                <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name
                <span style="color: #008000;">&#123;</span>
                    get<span style="color: #008000;">;</span>
                    set<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
                <span style="color: #008080; font-style: italic;">/// The frame that the event fires on</span>
                <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
                <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Keyframe
                <span style="color: #008000;">&#123;</span>
                    get<span style="color: #008000;">;</span>
                    set<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Our list of events in this animation clip</span>
            <span style="color: #008080; font-style: italic;">/// Animation clips do not require events, so this is marked as optional</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Framework</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ContentSerializer</span><span style="color: #008000;">&#40;</span>Optional <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span><span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">&gt;</span> Events
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The list of clip parts that we are breaking the original clip into</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>ClipPart<span style="color: #008000;">&gt;</span> ClipParts
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Next, we&#8217;ll need to modify the runtime project to add information about our events to the animations. Create a class in the SkinnedModelWindows project named AnimationEvent, with this in it:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080;">#region Using Statements</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endregion</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> SkinnedModel
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Information about an event in our animation</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> AnimationEvent
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The name of the event</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> EventName
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The time of the event</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> TimeSpan EventTime
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Now, we need to add our events store to the animation clip, as well as the clip name. So open up AnimationClip.cs, and add this to the end of the class:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Callback events for the animation clips</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008000;">&#91;</span>ContentSerializer<span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span> Events <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The name of the clip</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008000;">&#91;</span>ContentSerializer<span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>We also need to modify the constructor so that we can pass in the list of animation events when we create the clip. Our new constructor looks like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Constructs a new animation clip object.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> AnimationClip<span style="color: #008000;">&#40;</span>TimeSpan duration, List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> keyframes, List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span> events, <span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Duration <span style="color: #008000;">=</span> duration<span style="color: #008000;">;</span>
            Keyframes <span style="color: #008000;">=</span> keyframes<span style="color: #008000;">;</span>
            Events <span style="color: #008000;">=</span> events<span style="color: #008000;">;</span>
            Name <span style="color: #008000;">=</span> name<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Almost there. We need to modify the SkinnedModelProcessor class so that it reads in our XML files describing our animations and stores them in the model file that it generates, replacing the original animation (the Take 001). So, in SkinnedModelProcessor.cs, in the ProcessAnimations function, we need to first check if an animation definition file exists that we will use to override the ones in the model. By having this check, it means that we don&#8217;t need to create an animation definition for every skinned model, just the ones that we want custom animations on. You&#8217;ll also need to modify the ProcessAnimations function to take two extra parameters, which are the ContentProcessorContext and ContentIdentity. We use these to get information about the current file we are processing, so we can look for an animation definition with the same name. The below code is the updated ProcessAnimations function:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Converts an intermediate format content pipeline AnimationContentDictionary</span>
        <span style="color: #008080; font-style: italic;">/// object to our runtime AnimationClip format.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationClip<span style="color: #008000;">&gt;</span> ProcessAnimations<span style="color: #008000;">&#40;</span>
            AnimationContentDictionary animations, IList<span style="color: #008000;">&lt;</span>BoneContent<span style="color: #008000;">&gt;</span> bones,
            ContentProcessorContext context, ContentIdentity sourceIdentity<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Build up a table mapping bone names to indices.</span>
            Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> boneMap <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> bones<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> boneName <span style="color: #008000;">=</span> bones<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>boneName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    boneMap<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>boneName, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Convert each animation in turn.</span>
            Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationClip<span style="color: #008000;">&gt;</span> animationClips<span style="color: #008000;">;</span>
            animationClips <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationClip<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// We process the original animation first, so we can use their keyframes</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationContent<span style="color: #008000;">&gt;</span> animation <span style="color: #0600FF; font-weight: bold;">in</span> animations<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                AnimationClip processed <span style="color: #008000;">=</span> ProcessAnimation<span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>, boneMap, animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, processed<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Check to see if there's an animation clip definition</span>
            <span style="color: #008080; font-style: italic;">// Here, we're checking for a file with the _Anims suffix.</span>
            <span style="color: #008080; font-style: italic;">// So, if your model is named dude.fbx, we'd add dude_Anims.xml in the same folder</span>
            <span style="color: #008080; font-style: italic;">// and the pipeline will see the file and use it to override the animations in the</span>
            <span style="color: #008080; font-style: italic;">// original model file.</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> SourceModelFile <span style="color: #008000;">=</span> sourceIdentity<span style="color: #008000;">.</span><span style="color: #0000FF;">SourceFilename</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> SourcePath <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDirectoryName</span><span style="color: #008000;">&#40;</span>SourceModelFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> AnimFilename <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFileNameWithoutExtension</span><span style="color: #008000;">&#40;</span>SourceModelFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            AnimFilename <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot;_Anims.xml&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> AnimPath <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>SourcePath, AnimFilename<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>AnimPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Add the filename as a dependency, so if it changes, the model is rebuilt</span>
                context<span style="color: #008000;">.</span><span style="color: #0000FF;">AddDependency</span><span style="color: #008000;">&#40;</span>AnimPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Load the animation definition from the XML file</span>
                AnimationDefinition AnimDef <span style="color: #008000;">=</span> context<span style="color: #008000;">.</span><span style="color: #0000FF;">BuildAndLoadAsset</span><span style="color: #008000;">&lt;</span>XmlImporter, AnimationDefinition<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ExternalReference<span style="color: #008000;">&lt;</span>XmlImporter<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>AnimPath<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Break up the original animation clips into our new clips</span>
                <span style="color: #008080; font-style: italic;">// First, we check if the clips contains our clip to break up</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span><span style="color: #008000;">&#40;</span>AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalClipName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// Grab the main clip that we are using</span>
                    AnimationClip MainClip <span style="color: #008000;">=</span> animationClips<span style="color: #008000;">&#91;</span>AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalClipName</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Now remove the original clip from our animations</span>
                    animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalClipName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Process each of our new animation clip parts</span>
                    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationDefinition<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipPart</span> Part <span style="color: #0600FF; font-weight: bold;">in</span> AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipParts</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #008080; font-style: italic;">// Calculate the frame times</span>
                        TimeSpan StartTime <span style="color: #008000;">=</span> GetTimeSpanForFrame<span style="color: #008000;">&#40;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">StartFrame</span>, AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalFrameCount</span>, MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        TimeSpan EndTime <span style="color: #008000;">=</span> GetTimeSpanForFrame<span style="color: #008000;">&#40;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">EndFrame</span>, AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalFrameCount</span>, MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;">// Get all the keyframes for the animation clip</span>
                        <span style="color: #008080; font-style: italic;">// that fall within the start and end time</span>
                        List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> Keyframes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Keyframe AnimFrame <span style="color: #0600FF; font-weight: bold;">in</span> MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Keyframes</span><span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">&gt;=</span> StartTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">&lt;=</span> EndTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                Keyframe NewFrame <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Keyframe<span style="color: #008000;">&#40;</span>AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Bone</span>, AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">-</span> StartTime, AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Transform</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                                Keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>NewFrame<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #008000;">&#125;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;">// Process the events</span>
                        List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span> Events <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">Events</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #008080; font-style: italic;">// Process each event</span>
                            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationDefinition<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipPart</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Event</span> <span style="color: #0600FF; font-weight: bold;">Event</span> <span style="color: #0600FF; font-weight: bold;">in</span> Part<span style="color: #008000;">.</span><span style="color: #0000FF;">Events</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                <span style="color: #008080; font-style: italic;">// Get the event time within the animation</span>
                                TimeSpan EventTime <span style="color: #008000;">=</span> GetTimeSpanForFrame<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Keyframe</span>, AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalFrameCount</span>, MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                                <span style="color: #008080; font-style: italic;">// Offset the event time so it is relative to the start of the animation</span>
                                EventTime <span style="color: #008000;">-=</span> StartTime<span style="color: #008000;">;</span>
&nbsp;
                                <span style="color: #008080; font-style: italic;">// Create the event</span>
                                AnimationEvent NewEvent <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AnimationEvent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                                NewEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventTime</span> <span style="color: #008000;">=</span> EventTime<span style="color: #008000;">;</span>
                                NewEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventName</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
                                Events<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>NewEvent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #008000;">&#125;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;">// Create the clip</span>
                        AnimationClip NewClip <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AnimationClip<span style="color: #008000;">&#40;</span>EndTime <span style="color: #008000;">-</span> StartTime, Keyframes, Events, Part<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        animationClips<span style="color: #008000;">&#91;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipName</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> NewClip<span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span>
                            <span style="color: #666666;">&quot;Input file does not contain any animations.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> animationClips<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets a TimeSpan value for a frame index in an animation</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> TimeSpan GetTimeSpanForFrame<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> FrameIndex, <span style="color: #6666cc; font-weight: bold;">int</span> TotalFrameCount, <span style="color: #6666cc; font-weight: bold;">long</span> TotalTicks<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">float</span> MaxFrameIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>TotalFrameCount <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">float</span> AmountOfAnimation <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>FrameIndex <span style="color: #008000;">/</span> MaxFrameIndex<span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">float</span> NumTicks <span style="color: #008000;">=</span> AmountOfAnimation <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>TotalTicks<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> TimeSpan<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">long</span><span style="color: #008000;">&#41;</span>NumTicks<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>What we do is process the original animations, so that all the keyframe data is there, then we check for an animation definition file and, if it exists, use it to replace the animation clips from the original model. We also need to modify ProcessAnimation to handle the new AnimationClip constructor:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Converts an intermediate format content pipeline AnimationContent</span>
        <span style="color: #008080; font-style: italic;">/// object to our runtime AnimationClip format.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> AnimationClip ProcessAnimation<span style="color: #008000;">&#40;</span>AnimationContent animation,
                                              Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> boneMap,
                                              <span style="color: #6666cc; font-weight: bold;">string</span> clipName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> keyframes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// For each input animation channel.</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationChannel<span style="color: #008000;">&gt;</span> channel <span style="color: #0600FF; font-weight: bold;">in</span>
                animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Channels</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Look up what bone this channel is controlling.</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> boneIndex<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>boneMap<span style="color: #008000;">.</span><span style="color: #0000FF;">TryGetValue</span><span style="color: #008000;">&#40;</span>channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, <span style="color: #0600FF; font-weight: bold;">out</span> boneIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>
                        <span style="color: #666666;">&quot;Found animation for bone '{0}', &quot;</span> <span style="color: #008000;">+</span>
                        <span style="color: #666666;">&quot;which is not part of the skeleton.&quot;</span>, channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Convert the keyframe data.</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationKeyframe keyframe <span style="color: #0600FF; font-weight: bold;">in</span> channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Keyframe<span style="color: #008000;">&#40;</span>boneIndex, keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span>,
                                               keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Transform</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Sort the merged keyframes by time.</span>
            keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Sort</span><span style="color: #008000;">&#40;</span>CompareKeyframeTimes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Animation has no keyframes.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span> <span style="color: #008000;">&lt;=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Animation has a zero duration.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> AnimationClip<span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span>, keyframes, <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, clipName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>OK, so now we can override animations in the models using our XML file. Before I show you an example file, there&#8217;s one last thing to do, which is to add in the event callback system into the runtime. So, we need to add in a place to register our event callbacks into the AnimationPlayer class. At the end of the &#8216;Fields&#8217; region, we need to add:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">// The delegate template for the event callbacks</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">delegate</span> <span style="color: #6666cc; font-weight: bold;">void</span> EventCallback<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> <span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// The reigstered events</span>
        Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;&gt;</span> registeredEvents <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;&gt;</span> RegisteredEvents
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> registeredEvents<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>And initialise the registeredEvents dictionary in the constructor:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">// Construct the event dictionaries for each clip</span>
        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> clipName <span style="color: #0600FF; font-weight: bold;">in</span> skinningData<span style="color: #008000;">.</span><span style="color: #0000FF;">AnimationClips</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Keys</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            registeredEvents<span style="color: #008000;">&#91;</span>clipName<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Now we can add events, so the last thing to do is to add the code that calls them, then we&#8217;ll be done. In the UpdateBoneTransforms function in AnimationPlayer, we need to modify it like so:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Helper used by the Update method to refresh the BoneTransforms data.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateBoneTransforms<span style="color: #008000;">&#40;</span>TimeSpan time, <span style="color: #6666cc; font-weight: bold;">bool</span> relativeToCurrentTime<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>currentClipValue <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidOperationException<span style="color: #008000;">&#40;</span>
                            <span style="color: #666666;">&quot;AnimationPlayer.Update was called before StartClip&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Store the previous time</span>
            TimeSpan lastTime <span style="color: #008000;">=</span> time<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Update the animation position.</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>relativeToCurrentTime<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                lastTime <span style="color: #008000;">=</span> currentTimeValue<span style="color: #008000;">;</span>
                time <span style="color: #008000;">+=</span> currentTimeValue<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Check for events</span>
                CheckEvents<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> time, <span style="color: #0600FF; font-weight: bold;">ref</span> lastTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// If we reached the end, loop back to the start.</span>
                <span style="color: #6666cc; font-weight: bold;">bool</span> hasLooped <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&gt;=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    hasLooped <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    time <span style="color: #008000;">-=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// If we've looped, reprocess the events</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>hasLooped<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    CheckEvents<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> time, <span style="color: #0600FF; font-weight: bold;">ref</span> lastTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&lt;</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&gt;=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> ArgumentOutOfRangeException<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;time&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// If the position moved backwards, reset the keyframe index.</span>
            <span style="color: #6666cc; font-weight: bold;">bool</span> HasResetKeyframe <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&lt;</span> currentTimeValue<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                HasResetKeyframe <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                currentKeyframe <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                skinningDataValue<span style="color: #008000;">.</span><span style="color: #0000FF;">BindPose</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CopyTo</span><span style="color: #008000;">&#40;</span>boneTransforms, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            currentTimeValue <span style="color: #008000;">=</span> time<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Read keyframe matrices.</span>
            IList<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> keyframes <span style="color: #008000;">=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Keyframes</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>currentKeyframe <span style="color: #008000;">&lt;</span> keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                Keyframe keyframe <span style="color: #008000;">=</span> keyframes<span style="color: #008000;">&#91;</span>currentKeyframe<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Stop when we've read up to the current time position.</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">&gt;</span> currentTimeValue<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>HasResetKeyframe<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Use this keyframe.</span>
                boneTransforms<span style="color: #008000;">&#91;</span>keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Bone</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Transform</span><span style="color: #008000;">;</span>
&nbsp;
                currentKeyframe<span style="color: #008000;">++;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>HasResetKeyframe<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    currentTimeValue <span style="color: #008000;">=</span> keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span><span style="color: #008000;">;</span>
                    HasResetKeyframe <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>And add the CheckEvents function:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Checks to see if any events have passed</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> CheckEvents<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> TimeSpan time, <span style="color: #0600FF; font-weight: bold;">ref</span> TimeSpan lastTime<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> eventName <span style="color: #0600FF; font-weight: bold;">in</span> registeredEvents<span style="color: #008000;">&#91;</span>currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Keys</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Find the event</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationEvent animEvent <span style="color: #0600FF; font-weight: bold;">in</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Events</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventName</span> <span style="color: #008000;">==</span> eventName<span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        TimeSpan eventTime <span style="color: #008000;">=</span> animEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventTime</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>lastTime <span style="color: #008000;">&lt;</span> eventTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&gt;=</span> eventTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #008080; font-style: italic;">// Call the event</span>
                            registeredEvents<span style="color: #008000;">&#91;</span>currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>eventName<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span>eventName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>So now we can define custom animations with events. Lets see it in action&#8230;</p>
<p>Add a new file to your content project, giving it the same name as the model, but with _Anims.xml. In our case, our model file is dude.fbx, so we want dude_Anims.xml. We don&#8217;t actually want the content pipeline to build this directly, so set the Build Action property to None, the Content Processor to No Processing Required, and Copy to Output Directory to Do not copy. Our XML looks like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;XnaContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Asset</span> <span style="color: #000066;">Type</span>=<span style="color: #ff0000;">&quot;SkinnedModelPipeline.AnimationDefinition&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- The original name of the clip we are breaking up --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;OriginalClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Take 001<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/OriginalClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- The total number of frames in the original clip --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;OriginalFrameCount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/OriginalFrameCount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- The new parts we want --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ClipParts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #808080; font-style: italic;">&lt;!-- Each item is one of our new clips --&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Idle<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fire<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>51<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- We can register events in this clip, so we can know when certain frames are hit --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Events<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FireFrame<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Keyframe<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>70<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Keyframe<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Events<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ClipParts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Asset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/XnaContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</p>
<p>Now we can play our new clips like normal. We can also add callbacks for events. For example, the FireFrame event, we add like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">            <span style="color: #008080; font-style: italic;">// Create an animation player, and start decoding an animation clip.</span>
            animationPlayer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AnimationPlayer<span style="color: #008000;">&#40;</span>skinningData<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Register an event</span>
            animationPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisteredEvents</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Fire&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FireFrame&quot;</span>, <span style="color: #008000;">new</span> AnimationPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">EventCallback</span><span style="color: #008000;">&#40;</span>OnFire<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            AnimationClip clip <span style="color: #008000;">=</span> skinningData<span style="color: #008000;">.</span><span style="color: #0000FF;">AnimationClips</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Fire&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            animationPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">StartClip</span><span style="color: #008000;">&#40;</span>clip<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

</p>
<p>And our function just looks like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnFire<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> EventName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Do something here like create a bullet</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>So there you have it. You can download the updated sample <a href="downloads/skinnedmodelsample/SkinningSample_4_0_WithCustomAnims.zip">here</a>. You can use the &#8217;1&#8242; and &#8217;2&#8242; keys to switch between animation clips. The second one has a callback registered to it. One thing to note is that you&#8217;ll have to make sure you do a Rebuild Solution if you&#8217;re adding an animation XML to an existing model, because the content pipeline doesn&#8217;t know that the model depends on the animation definition until after it has built it once with the animation file there. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Texture Atlas (Sprite Sheet) Generator</title>
		<link>http://www.gogo-robot.com/2010/03/20/texture-atlas-sprite-sheet-generator/</link>
		<comments>http://www.gogo-robot.com/2010/03/20/texture-atlas-sprite-sheet-generator/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 16:47:50 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[sprite sheet]]></category>
		<category><![CDATA[texture atlas]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=206</guid>
		<description><![CDATA[A texture atlas, or sprite sheet, is a single image containing a number of smaller textures or sprites. This is useful as it is more efficient for the graphics card to process (it doesn&#8217;t have to keep switching textures when drawing different textures, as it can just use the single texture and sample from different [...]]]></description>
			<content:encoded><![CDATA[<p>A texture atlas, or sprite sheet, is a single image containing a number of smaller textures or sprites. This is useful as it is more efficient for the graphics card to process (it doesn&#8217;t have to keep switching textures when drawing different textures, as it can just use the single texture and sample from different parts of it). It is also faster to load into RAM, as you are only loading in one image, as opposed to several smaller ones, so the loading can be done in one stage.</p>
<p><span id="more-206"></span></p>
<p>It is useful to be able to quickly and easily generate texture atlases from a number of source sprites to speed up development. A useful tool when developing using the XNA framework is the <a href="http://creators.xna.com/en-GB/sample/spritesheet">SpriteSheet Sample</a> available on the XNA Creators Club website. One downside of this, however, is that you must still manually generate the XML file list by hand, which can be a pain if you have a lot of textures to place on the sprite sheet. Another is that it is XNA only <img src='http://www.gogo-robot.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Because we also do development on the iPhone, it was useful to have a similar generator for that platform, as well as for the XNA framework, so we created a tool to easily generate the texture atlases for us. The packing code is based on the SpriteSheet Sample code, though the tool is written in plain .NET, so does not require the XNA framework to be installed (though it does require the .NET framework). The tool can produce a PNG file with the combined textures, as well as an accompanying binary file, called a TXA file, with the information on each of the packed textures. It also supports removing transparent borders from textures to produce a more compact output. It can also optionally produce a C style header with enums in, so you don&#8217;t have to look up the textures by their names.</p>
<p>The help files for the texture atlas generator tool contain information on the format of the TXA files, so you can write your own loaders if you wish.</p>
<p>As well as the PNG + TXA combination, the tool can produce an XNA XML file (and optionally a C# file with enums in) which can be imported into your Content project to build the sprite sheet during compile time. You do need to include the XNA projects in yours to access the Content Processor and runtime types. The runtime library also includes extensions to the SpriteBatch class, to make it easier to draw using the textures.</p>
<p>Finally, there is a runtime library to load the texture atlas on an iPhone. The iPhone code uses the PVRTexture class from Apple&#8217;s sample code, so you can convert the PNG to a PVR if you wish using Apple&#8217;s texturetool (though this can be problematic as the textures may &#8216;bleed&#8217; into each other). The iPhone runtime library also requires <a href="http://www.zlib.net/">zlib</a> and <a href="http://www.libpng.org/pub/png/libpng.html">libpng</a></p>
<p>Each zip contains a Readme.txt file containing license information and other tips. You&#8217;re pretty much free to do what you want with these things, use them however you see fit (commercial or non-commercial), but remember they are provided as-is, and we accept no responsibility for anything <img src='http://www.gogo-robot.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We&#8217;ve tried to tidy them up to make them usable by other people, but if you&#8217;ve got any problems or questions, post in the comments and we&#8217;ll try and help. There may be bugs in these, so let us know if you find any!</p>
<ul>
<li><a href="/downloads/textureatlas/Texture%20Atlas%20Generator.zip">Texture Atlas Generator</a></li>
<li><a href="/downloads/textureatlas/Texture%20Atlas%20-%20XNA.zip">XNA Runtime and Pipeline Libraries</a></li>
<li><a href="/downloads/textureatlas/Texture%20Atlas%20Runtime%20-%20iPhone.zip">iPhone Runtime</a> &#8211; Requires zlib and libpng</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2010/03/20/texture-atlas-sprite-sheet-generator/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 Flashlight (With SOS)</title>
		<link>http://www.gogo-robot.com/2010/03/19/windows-phone-7-flashlight-with-sos/</link>
		<comments>http://www.gogo-robot.com/2010/03/19/windows-phone-7-flashlight-with-sos/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 12:02:16 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[windows phone 7]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=199</guid>
		<description><![CDATA[I tried posting this as a comment in reply to this post, but the code got mangled, so I&#8217;m posting it here graphics.GraphicsDevice.Clear&#40; /* Check for touch panel being pressed */ TouchPanel.GetState&#40;&#41;.Count == 0 ? /* Touch panel released, so reset the timer. This is stored in the target elapsed time, so we don't have [...]]]></description>
			<content:encoded><![CDATA[<p>I tried posting this as a comment in reply to <a href="http://codecube.net/2010/03/windows-phone-7-flashlight/">this post</a>, but the code got mangled, so I&#8217;m posting it here <img src='http://www.gogo-robot.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">            graphics<span style="color: #008000;">.</span><span style="color: #0000FF;">GraphicsDevice</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span>
                <span style="color: #008080; font-style: italic;">/* Check for touch panel being pressed */</span>
            TouchPanel<span style="color: #008000;">.</span><span style="color: #0000FF;">GetState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">?</span>
                <span style="color: #008080; font-style: italic;">/* Touch panel released, so reset the timer. This is stored in the target elapsed time, so we don't have to create any variables :) We also turn off IsFixedTimeStep, so that TargetElapsedTime isn't used. */</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsFixedTimeStep</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span> <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>1<span style="color: #008000;">.</span>0f, gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalMilliseconds</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">Gray</span> <span style="color: #008000;">:</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">Gray</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span>
                <span style="color: #008080; font-style: italic;">/* Touch panel pressed, so do SOS */</span>
                <span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">7</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">13</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">15</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">17</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">18</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">19</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">21</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TargetElapsedTime</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Seconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">22</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span> <span style="color: #008000;">:</span>
                Color<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2010/03/19/windows-phone-7-flashlight-with-sos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

