<?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>Silverlight &#124; WPF &#124; Microsoft.Net &#187; code</title>
	<atom:link href="http://joel.neubeck.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net</link>
	<description>Simplifing structure without changing results</description>
	<lastBuildDate>Wed, 26 May 2010 18:43:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Developing a casual game with Silverlight &#8211; Module 5</title>
		<link>http://joel.neubeck.net/2009/05/casual-game-m5-expression-newsletter/</link>
		<comments>http://joel.neubeck.net/2009/05/casual-game-m5-expression-newsletter/#comments</comments>
		<pubDate>Fri, 22 May 2009 17:18:47 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[casual games]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Expression Newsletter]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=396</guid>
		<description><![CDATA[This week Microsoft published the latest issue of the Expression Newsletter. If you have not seen the newsletter its a great series of articles focused on using Silverlight and the Expression tools to create amazing rich interactive solutions. In this latest issue I was asked to contribute the fifth of a six part series of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.microsoft.com/expression/news-press/newsletter/"><img class="alignnone size-full wp-image-236" title="Microsoft Expression" src="http://joel.neubeck.net/wp-content/uploads/2008/09/microsoft_expression_logo.gif" alt="" width="191" height="62" /></a>This week Microsoft published the latest issue of the Expression Newsletter.  If you have not seen the newsletter its a great series of articles focused on using Silverlight and the Expression tools to create amazing rich interactive solutions.  In this latest issue I was asked to contribute the fifth of a six part series of articles on  <a href="http://expression.microsoft.com/en-us/dd835381.aspx">exploring the process of designing and building a casual online game in Silverlight .</a>.   Here is what  the series will include.</p>
<ul>
<li>Module 1: Getting Started – Architecture / framework</li>
<li>Module 2: Movement and collision detection</li>
<li>Module 3: Design – Sprites, boards and dialogs</li>
<li>Module 4: Animations and sound</li>
<li><a href="http://expression.microsoft.com/en-us/dd835381.aspx"><strong>Module 5: Initialization and Deployment</strong></a></li>
<li>Module 6: Advanced concepts (Physics, Multiplayer, Optimization)</li>
</ul>
<p>Make sure to check out the article at <a href="http://www.microsoft.com/expression/news-press/newsletter/">http://www.microsoft.com/expression/news-press/newsletter/</a></p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/ENM5/Game.zip');" href="/wp-content/uploads/2009/05/ENM5/Game.zip">Game.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/05/casual-game-m5-expression-newsletter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Developing a Casual Game with Siverlight 2 – Module 4</title>
		<link>http://joel.neubeck.net/2009/03/casual-game-m4-expression-newsletter/</link>
		<comments>http://joel.neubeck.net/2009/03/casual-game-m4-expression-newsletter/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 15:32:09 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[casual games]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Expression Newsletter]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=382</guid>
		<description><![CDATA[This week Microsoft published the latest issue of the Expression Newsletter. If you have not seen the newsletter its a great series of articles focused on using Silverlight and the Expression tools to create amazing rich interactive solutions. In this latest issue I was asked to contribute the fourth of a six part series of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.microsoft.com/expression/news-press/newsletter/"><img class="alignnone size-full wp-image-236" title="Microsoft Expression" src="http://joel.neubeck.net/wp-content/uploads/2008/09/microsoft_expression_logo.gif" alt="" width="191" height="62" /></a>This week Microsoft published the latest issue of the Expression Newsletter.  If you have not seen the newsletter its a great series of articles focused on using Silverlight and the Expression tools to create amazing rich interactive solutions.  In this latest issue I was asked to contribute the fourth of a six part series of articles on  <a href="http://expression.microsoft.com/en-us/dd569746.aspx">exploring the process of designing and building a casual online game in Silverlight 2.</a>.   Here is what  the series will include.</p>
<ul>
<li>Module 1: Getting Started – Architecture / framework</li>
<li>Module 2: Movement and collision detection</li>
<li><a href="http://expression.microsoft.com/en-us/dd434645.aspx">Module 3: Design – Sprites, boards and dialogs</a></li>
<li><strong>Module 4: Animations and sound</strong></li>
<li>Module 5: Initialization and Deployment</li>
<li>Module 6: Advanced concepts (Physics, Multiplayer, Optimization)</li>
</ul>
<p>Make sure to check out the article at <a href="http://www.microsoft.com/expression/news-press/newsletter/">http://www.microsoft.com/expression/news-press/newsletter/</a></p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/ENM3/Game.zip');" href="/wp-content/uploads/2009/03/ENM4/Game.zip">Game.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/03/casual-game-m4-expression-newsletter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Developing a casual game with Silverlight 2 &#8211; Module 3</title>
		<link>http://joel.neubeck.net/2009/01/casual-game-m3-expression-newsletter/</link>
		<comments>http://joel.neubeck.net/2009/01/casual-game-m3-expression-newsletter/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 21:15:45 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[casual games]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Expression Newsletter]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=331</guid>
		<description><![CDATA[This week Microsoft published the latest issue of the Expression Newsletter. If you have not seen the newsletter its a great series of articles focused on using Silverlight and the Expression tools to create amazing rich interactive solutions. In this latest issue I was asked to contribute the third of a six part series of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.microsoft.com/expression/news-press/newsletter/"><img class="alignnone size-full wp-image-236" title="Microsoft Expression" src="http://joel.neubeck.net/wp-content/uploads/2008/09/microsoft_expression_logo.gif" alt="" width="191" height="62" /></a>This week Microsoft published the latest issue of the Expression Newsletter.  If you have not seen the newsletter its a great series of articles focused on using Silverlight and the Expression tools to create amazing rich interactive solutions.  In this latest issue I was asked to contribute the third of a six part series of articles on  <a href="http://expression.microsoft.com/en-us/dd434645.aspx">exploring the process of designing and building a casual online game in Silverlight 2.</a>.   Here is what  the series will include.</p>
<ul>
<li>Module 1: Getting Started – Architecture / framework</li>
<li>Module 2: Movement and collision detection</li>
<li><a href="http://expression.microsoft.com/en-us/dd434645.aspx"><strong>Module 3: Design – Sprites, boards and dialogs</strong></a></li>
<li>Module 4: Animations and sound</li>
<li>Module 5: Initialization and Deployment</li>
<li>Module 6: Advanced concepts (Physics, Multiplayer, Optimization)</li>
</ul>
<p>Make sure to check out the article at <a href="http://www.microsoft.com/expression/news-press/newsletter/">http://www.microsoft.com/expression/news-press/newsletter/</a></p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/ENM3/Game.zip');" href="/wp-content/uploads/2009/01/ENM3/Game.zip">Game.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/01/casual-game-m3-expression-newsletter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transformation Matrix in Silverlight 2</title>
		<link>http://joel.neubeck.net/2008/09/transformation-matrix-in-silverlight-2/</link>
		<comments>http://joel.neubeck.net/2008/09/transformation-matrix-in-silverlight-2/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 05:53:58 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[MatrixTransform]]></category>
		<category><![CDATA[RenderTransform]]></category>
		<category><![CDATA[Rotate]]></category>
		<category><![CDATA[Scale]]></category>
		<category><![CDATA[Skew]]></category>
		<category><![CDATA[Translate]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/09/transformation-matrix-in-silverlight-2/</guid>
		<description><![CDATA[In my exploration of Silverlight I have looked at a ton of code samples, and not once have I seen an example that chooses MatrixTransform as the class used to render a transformation.&#160; We all should be familiar with the four transform classes Silverlight provides for 2-D transformations.&#160; Each allows us to manipulate the underlying [...]]]></description>
			<content:encoded><![CDATA[<p>In my exploration of Silverlight I have looked at a ton of code samples, and not once have I seen an example that chooses MatrixTransform as the class used to render a transformation.&#160; We all should be familiar with the four transform classes Silverlight provides for 2-D transformations.&#160; Each allows us to manipulate the underlying matrix without having to understand how the matrix is structured.&#160; All of them can be grouped into a single TransformGroup to apply multiple transformations to a single object.</p>
<ul>
<li>TransformGroup
<ul>
<li>RotateTransform – Rotates by an angle </li>
<li>ScaleTransform – Scales by a a given X and Y </li>
<li>SkewTransform – Skews an element by an X and Y angle </li>
<li>TranslateTransform – Moves and object by a specified X and Y </li>
</ul>
</li>
</ul>
<p dir="ltr">As an alternative, you can use the MatrixTransform as a way to manipulate a matrix directly.</p>
<h2>What is a Matrix</h2>
<p>In Silverlight a matrix is a 3&#215;3 array of numbers used to define <strong>affine</strong> transformations.&#160; Here is a great definition of a Affine transformation taken from an excellent tutorial on using matrices in Flash.</p>
<p> <a href="http://www.senocular.com/flash/tutorials/transformmatrix/" target="blank"><br />
<blockquote>
<p>Affine transformations are transformations that preserve collinearity and relative distancing in a transformed coordinate space. This means points on a line will remain in a line after an affine transformation is applied to the coordinate space in which that line exists.</p>
</blockquote>
<p> </a>
<p>Silverlight uses row-major matrices, such that vectors are expressed as rows and not column vectors.&#160; Here is what the matrix structure looks like.</p>
<table cellspacing="0" cellpadding="2" width="230" border="1">
<tbody>
<tr>
<td valign="top" width="91">M11 (1.0)</td>
<td valign="top" width="99">M12 (0.0)</td>
<td valign="top" width="38">0</td>
</tr>
<tr>
<td valign="top" width="91">M21 (0.0)</td>
<td valign="top" width="99">M22 (1.0)</td>
<td valign="top" width="38">0</td>
</tr>
<tr>
<td valign="top" width="91">Offset X (0.0)</td>
<td valign="top" width="99">Offset Y (0.0)</td>
<td valign="top" width="38">1</td>
</tr>
</tbody>
</table>
<p>Since Silverlight only supports affine transforms, the values in the right column are always 0,0,1.&#160; Below is an example of a Silverlight UserControl that demonstrates how manipulating each of the matrices values, will transform a rectangle.</p>
<p> <iframe src="/wp-content/uploads/2008/09/Matrix/" width="500" height="200"></iframe>
<p>In my demonstration, using the appropriate TextBox&#160; you can rotate, scale, skew, and move the rectangle. For example, if you set M12 equal to 0.5 and M21 equal to -0.5 you will rotate the rectangle 45 deg.&#160; If you set M11 and M22 equal to 1.5 you will scale the rectangle proportionately to approximately one and half times its original size. </p>
<p>Procedurally, these values can be set by defining a Matrix struct and setting the appropriate property (M11, M12, M21, M22, OffsetX, OffsetY).&#160; The matrix can be applied to an objects RenderTransform by simply setting the MatrixTransform.Matrix property.</p>
</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">Matrix martix = new Matrix(1.5,0.5,-0.5,1.5,0,0);
MatrixTransform transform = new MatrixTransform();
transform.Matrix = matrix;
rectangle.RenderTransform = transform;</pre></div></div>

<p>Later in the week I will post an example that uses a MatrixTransform to demonstrate an animation that reacts to mouse movement.&#160; Nothing crazy, but a nice example of where a Matrix can create an interesting effect with very little code.</p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/Matrix.zip');" href="/wp-content/uploads/2008/09/Matrix/MatrixExample.zip">MatrixExample.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/09/transformation-matrix-in-silverlight-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Loading images in Silverlight 2</title>
		<link>http://joel.neubeck.net/2008/06/loading-images-in-silverlight-2/</link>
		<comments>http://joel.neubeck.net/2008/06/loading-images-in-silverlight-2/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 06:29:31 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[BitmapImage]]></category>
		<category><![CDATA[Build Action]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Uri]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/06/loading-images-in-silverlight-2/</guid>
		<description><![CDATA[Reading through the Silverlight.net forum I still see a ton of people struggling with how to load an image procedurally. I thought it would be beneficial to included a quick sample of four different ways you can set the Image.Source property within Silverlight 2. Image 1 &#8211; Resource Loaded via XAML &#8211; The easiest and [...]]]></description>
			<content:encoded><![CDATA[<p>Reading through the Silverlight.net forum I still see a ton of people struggling with how to load an image procedurally. I thought it would be beneficial to included a quick sample of four different ways you can set the Image.Source property within Silverlight 2.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading1.png"><img title="image_loading1" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="316" alt="image_loading1" src="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading1-thumb.png" width="416" align="left" border="0" /></a></p>
<p>  <br style="clear: both" /><br />
<hr /><strong>Image 1 &#8211; Resource Loaded via XAML</strong> &#8211; The easiest and most common way to load an image is to include the image in your project and set its &quot;Build Action&quot; to Resource. This will embedded the image within the primary assembly which gets packaged in your projects XAP file. Here is what that assembly looks like if you explore it with Reflector.
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading3.png"><img title="image_loading3" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="251" alt="image_loading3" src="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading3-thumb.png" width="560" align="left" border="0" /></a></p>
<p>  <br style="clear: both" />To reference this embedded resource within xaml, you can set the source attribute equal to the following
<pre>&lt;Image Source=&quot;ImageSource;component/1.jpg&quot;…&gt;</pre>
<hr /><strong>Image 2 &#8211; Resource Loaded procedurally</strong> &#8211; In the event that you need to swap or load an images source procedurally, you can simply load up a BitmapImage via a relative URI and set the Image.Source equal to this object.</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">//Image 2 - Loaded via bitmap image data
// - Build Action=Resource
// - Copy to Output Directory = Do Not Copy
BitmapImage bmpImg2 = new BitmapImage();
Uri uri2 = new Uri(&amp;quot;2.jpg&amp;quot;, UriKind.Relative);
bmpImg2.UriSource = uri2;
image2.Source = bmpImg2;</pre></div></div>

<hr />
<p><strong>Image 3 &#8211; Build Action = Content</strong> – If you do not desire to embed an image within your assembly, you can set its build action to “Content” and that image will be packaged within the XAP.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading4.png"><img title="XAP File" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="105" alt="XAP File" src="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading4-thumb.png" width="311" align="left" border="0" /></a> </p>
<p><br style="clear: both" /></p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">//Image 3 - Load image that is included in the XAP file
// - Build action = Content
// - Copy to Output Directory = Do Not Copy
BitmapImage bmpImg3 = new BitmapImage();
Uri uri3 = new Uri(&amp;quot;/3.jpg&amp;quot;, UriKind.Relative);
bmpImg3.UriSource = uri3;
image3.Source = bmpImg3;</pre></div></div>

<p>(Note: The image file name in the URI is proceeded with a front slash (/).&#160; This is required to indicate that the image is relative to the location of the assembly.)</p>
<hr />
<p><strong>Image 4 &#8211; Build Action = None / Copy to Output Directory = Copy always </strong>- In the instance that you don’t want the image to be downloaded locally (packaged in XAP), you can set the “Build Action” equal to “None” and set the “Copy to Output Directory” equal to “Copy always”.&#160; <a href="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading5.png"><img title="/bin directory" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="188" alt="/bin directory" src="http://joel.neubeck.net/wp-content/uploads/2008/06/image-loading5-thumb.png" width="415" align="left" border="0" /></a> </p>
<p><br style="clear: both" /></p>
<p>Using the “TestPage.html” page which is automatically generated in your projects “bin” directory you can reference the image location relatively, just as you did in sample 3.</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">//Image 4 - Load image that is located at some relative url
// - Build action = None
// - Copy to Output Directory = Copy always 
//      (Note: I had to manually copy the image to 
//       my web projects ClientBin directory)
BitmapImage bmpImg4 = new BitmapImage();
Uri uri4 = new Uri(&amp;quot;/4.jpg&amp;quot;, UriKind.Relative);
bmpImg4.UriSource = uri4;
image4.Source = bmpImg4;</pre></div></div>

<p>Code: <a onclick="javascript: pageTracker._trackPageview(&#39;/code/ImageSource.zip&#39;);" href="/wp-content/uploads/2008/06/ImageSource.zip">ImageSource.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/06/loading-images-in-silverlight-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Silverlight 2 Video Player pushed to CodePlex</title>
		<link>http://joel.neubeck.net/2008/06/silverlight-2-video-player-pushed-to-codeplex/</link>
		<comments>http://joel.neubeck.net/2008/06/silverlight-2-video-player-pushed-to-codeplex/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 18:26:03 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[CodePlex]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Tim Heuer]]></category>
		<category><![CDATA[Video Player]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=166</guid>
		<description><![CDATA[Yesterday Tim Heuer made a great suggestion that we submit our collaboration on a  Silverlight 2 Video Player as Open Source to CodePlex. You can now find the latest source at http://www.codeplex.com/sl2videoplayer.  As we find any &#8220;undocumented features&#8221; or add new and exciting ehancments we will push these up to CodePlex.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codeplex.com/sl2videoplayer"><img class="alignleft size-full wp-image-167" title="codeplex-logo_thumb" src="http://joel.neubeck.net/wp-content/uploads/2008/06/codeplex-logo_thumb.jpg" alt="" width="235" height="92" /></a>Yesterday Tim Heuer made a great suggestion that we submit our collaboration on a  Silverlight 2 Video Player as Open Source to CodePlex.  You can now find the latest source at <a title="http://www.codeplex.com/sl2videoplayer" href="http://www.codeplex.com/sl2videoplayer">http://www.codeplex.com/sl2videoplayer</a>.  As we find any &#8220;undocumented features&#8221; or add new and exciting ehancments we will push these up to CodePlex.</p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/06/silverlight-2-video-player-pushed-to-codeplex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight 2 &#8211; Media Player with Marker support</title>
		<link>http://joel.neubeck.net/2008/06/sl2b2-media-player-markers/</link>
		<comments>http://joel.neubeck.net/2008/06/sl2b2-media-player-markers/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 17:10:32 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[MediaElement]]></category>
		<category><![CDATA[Slider]]></category>
		<category><![CDATA[Tim Heuer]]></category>
		<category><![CDATA[TimeLineMarker]]></category>
		<category><![CDATA[Video Player]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/06/sl2b2-media-player-markers/</guid>
		<description><![CDATA[Please note: This sample was made into a Code Plex project and is maintained there. Please download all source from http://www.codeplex.com/sl2videoplayer/ Back in April I created a very simple Video Player in Silverlight 2 Beta 1 which Tim Heuer took to a whole new level. In his first pass he added dynamic resizing and initParams [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Please note</strong>: This sample was made into a Code Plex project and is maintained there.  Please download all source from <a href="http://www.codeplex.com/sl2videoplayer/">http://www.codeplex.com/sl2videoplayer/</a></p></blockquote>
<p>Back in April I created a very simple Video Player in Silverlight 2 Beta 1 which <a href="http://timheuer.com" target="_blank">Tim Heuer</a> took to a whole new level. In his first pass he added dynamic resizing and initParams to load the video source. Then back a few weeks ago Tim brought it up to speed for Beta 2 and integrated the &quot;VisualStateManager&quot; to get the ToggleButton to function correctly. I love how it turned out. </p>
<p>One thing that I really wanted to include in my first version was control for TimelineMarkers. Unfortunately in Beta 1 I had some issues with dynamic markers, and decided to hold off until Beta 2 was released. Microsoft Expression Encoder 2 is a great tool and makes it very easy to insert markers that fire events during video playback. Markers are very simple, they define a TimeSpan of when to fire the &quot;MarkerReached&quot; event, and define some text that describes the marker.&#160;&#160; In my example I will use this text as the copy for my Marker Popup.&#160; Here is how I chose to visualize my markers in the video player. </p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/06/videoplayer-c2.png"><img title="videoplayer_c2" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="114" alt="videoplayer_c2" src="http://joel.neubeck.net/wp-content/uploads/2008/06/videoplayer-c2-thumb.png" width="292" align="left" border="0" /></a> </p>
<p>To achieve this effect, I created a custom UserControl called &quot;Marker.xaml&quot;. This control contains a single animation which will fade in the text, and fade it out again after a predefined amount of time.&#160; The control is comprised of a TextBlock and a “Arrow” path that can be moved left and right within the second row of a Grid control.&#160; This gives me the ability to control where the Arrow visualizes in relation to my Timeline Slider control.</p>
<p>Based on the number of markers encoded in the video an equal number of markers will be placed in the “MediaControl”.&#160; There position on the slider time line is determined by calculating the following: </p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/06/videoplayer-c31.png"><img title="videoplayer_c3" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="91" alt="videoplayer_c3" src="http://joel.neubeck.net/wp-content/uploads/2008/06/videoplayer-c3-thumb1.png" width="500" align="left" border="0" /></a> </p>
<p>   <br style="clear: both" />The position is not absolute, but close enough to where the “Thumb” in the slider control will exist at that moment the marker should popup.&#160;&#160; Once I have placed a marker into the appropriate Grid on my MediaControl I store it in a generic Dictionary keyed off of the time it should be displayed. This allows me to very quickly find the UserControl when the Media.MarkerReached event fires or the player goes into fullscreen mode.&#160;&#160; In the event that the user wants to play the video in fullscreen, I must reposition my markers relative to the new ActualWidth of the&#160; sliderTimeline.&#160; </p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/06/videoplayer-c4.png"><img title="videoplayer_c4" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="117" alt="videoplayer_c4" src="http://joel.neubeck.net/wp-content/uploads/2008/06/videoplayer-c4-thumb.png" width="500" align="left" border="0" /></a> </p>
<p>  <br style="clear: both" />
<p>Here is how it all turned out.&#160; </p>
<p><iframe src="/wp-content/uploads/2008/06/VideoPlayerMarkers/default.html" width="500" height="240"></iframe></p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview(&#39;/code/VideoPlayerMarkers.zip&#39;);" href="http://www.codeplex.com/sl2videoplayer/">Code Plex</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/06/sl2b2-media-player-markers/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Silverlight 2 MVC Game Framework</title>
		<link>http://joel.neubeck.net/2008/06/silverlight-2-game-framework-example/</link>
		<comments>http://joel.neubeck.net/2008/06/silverlight-2-game-framework-example/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 22:55:08 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[casual games]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Collision]]></category>
		<category><![CDATA[Elastic Collision]]></category>
		<category><![CDATA[Inelastic Collision]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/06/silverlight-2-game-framework-example/</guid>
		<description><![CDATA[Last week I presented a session at DesertCodeCamp 2008 on Developing Casual Games with Silverlight 2. Excluding some technical difficulties, getting my MacBook to connect to dual projectors, the presentation went well. There is certainly interest in the community to begin using Silverlight as a casual gaming platform. The goal of this presentation was to [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I presented a session at <a href="http://desertcodecamp.com" target="_blank">DesertCodeCamp</a> 2008 on Developing Casual Games with Silverlight 2. Excluding some technical difficulties, getting my MacBook to connect to dual projectors, the presentation went well.  There is certainly interest in the community to begin using Silverlight as a casual gaming platform.</p>
<p>The goal of this presentation was to create a more “developer” focused exploration into a development architecture one could use for building a casual game. In this example, one which leverages pixel-based movement.  As with everything in development, there is no real right or wrong architecture, just proven patterns, that have proven scalability, flexibility and efficiency.</p>
<h2>Concept</h2>
<p>Build a simple game where a player has to move around a box and avoid a series of randomly moving spheres.  Each sphere can collide with both the bounds of the box, each other and the player.  The player can only be collided with 5 times or the game is over.  Player movement is controlled by hitting a combination of arrow keys which changes the vector angle of the players movement.  The players speed is consistent, until that player collides with one of the spheres.  The behavior of the collision will change based on the element being collided with..</p>
<h2>Framework</h2>
<p>Last fall Microsoft released its first version of the Model-View-Controller (MVC) framework for ASP.NET as a way to help developers implement this proven separation pattern into ASPX site design. If you have not got a chance to use I strongly recommend giving it a try.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/06/cc-game-solution.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="VS 2008 Solution" src="http://joel.neubeck.net/wp-content/uploads/2008/06/cc-game-solution-thumb.png" border="0" alt="VS 2008 Solution" width="241" height="594" align="left" /></a>At a very high level MVC divides an application&#8217;s implementation into three components: models, views, and controller.  This “separation” is used specifically as a way to improve a developers ability to decouple the presentation layer from the business logic.  In game development, MVC is an excellent way to build a foundation which simplifies a developers ability to control state such as movement and collision detection.  Unfortunately a formal MVC framework does not exist for Silverlight 2, but implementing the pattern is pretty simple.  The image to left illustrates how I have implemented the MCV pattern in my example project.</p>
<p>Exploring further you will see that I do not consider “page.xaml” a view. This is intentional.  page.xaml is simply a way to get my controller instantiated.  All game elements will be inserted into my “Shell.xaml” view by my controller, and this UserControl will be inserted into the page’s LayoutRoot after the page’s xaml has been loaded.  My controller will get a reference to this root UIElement via constructor dependency injection, a common approach seen in MVC implementations.  Here is the code found within page.xaml.cs.</p>
<p><br style="clear: both" /></p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">public partial class Page : UserControl
{
    private Controllers.Controller _controller;
    private Views.Shell _shell = new Views.Shell();
    public Views.Shell Shell
    {
        get { return _shell; }
        set { _shell = value; }
    }
&nbsp;
    public Page()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(Page_Loaded);
    }
&nbsp;
    void Page_Loaded(object sender, RoutedEventArgs e)
    {
        LayoutRoot.Children.Add(_shell);
        _controller = new Controllers.Controller(this);
        _controller.Initialize();
    }
}</pre></div></div>

<h2>Controller</h2>
<p>In this game I have a single controller which acts as the central nervous system of my game. It controls the following:</p>
<ul>
<li>Primary game timer (tick)
<ul>
<li>Moves Player, Balls and checks for Collisions</li>
</ul>
</li>
<li>Inserts the appropriate dialogs and listens to events from each
<ul>
<li>Start, End, Next Level</li>
</ul>
</li>
<li>Listening for events from my primary model
<ul>
<li>Collision, NextLevel, GameOver and StopMovement</li>
</ul>
</li>
<li>Captures the approriate keyboard inputs
<ul>
<li>Left, Right, Up, Down, Left-Up, Left-Down, Right-Up, Right-Down</li>
</ul>
</li>
</ul>
<h2>Game Model</h2>
<p>The controller instantiates and holds a reference to my primary game model which will maintain the games state and expose any methods used to interact with the “Player” and “Hazards” [ball]).  The model is the single places that knows how to start a level, insert the player and place each of the balls into a level.  When events occur like the player collides with a ball, the model fires an event to the controller indicating what transpired.  The controller decides what this means visually to the game play (updates the “Shell” to indicate a new Hit count).  The model maintains state so it will be responsible for deciding when the game is over.  A game is over when either time has expired (15 seconds) or five collisions have occurred.  As with a collision, the model will fire an event to the controller when the game is over.</p>
<h2>Behaviors</h2>
<p>Part of building this sample was to build upon some of the previous work I have done on spherical collisions.  Is previous posts, I have shown how to react to both an elastic and inelastic collision.  In this example I refer to elastic behavior as “Deflect” and inelastic as “Bump”.  The idea is that if I build an object oriented methodology of defining collision behavior, one based on inheritance, I can expand the types of hazards as I develop new behaviors.  For example, the next behavior I intend to develop is one which hazards chases the player, when the hazard gets within a specified proximity of the player.</p>
<p>Here is the game and source.</p>
<p><iframe src="/wp-content/uploads/2008/06/CodeCampGame/default.html" width="400" height="400"></iframe></p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/CodeCampGame.zip');" href="/wp-content/uploads/2008/06/CodeCampGame/CodeCampGame.zip">CodeCampGame.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/06/silverlight-2-game-framework-example/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Spherical elastic and inelastic collisions in Silverlight</title>
		<link>http://joel.neubeck.net/2008/05/spherical-collisions/</link>
		<comments>http://joel.neubeck.net/2008/05/spherical-collisions/#comments</comments>
		<pubDate>Wed, 21 May 2008 21:51:40 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Deflection]]></category>
		<category><![CDATA[Elastic Collision]]></category>
		<category><![CDATA[Inelastic Collision]]></category>
		<category><![CDATA[Physics]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/05/spherical-collisions/</guid>
		<description><![CDATA[I recently took an interest in using some very basic physics within Silverlight 2. I took physics nearly 12 years ago and am certainly rusty, but thought it would be fun to simulate he effect two spheres have when they collide. Their are two types of collision; a perfectly elastic collision where there is no [...]]]></description>
			<content:encoded><![CDATA[<p>I recently took an interest in using some very basic physics within Silverlight 2. I took physics nearly 12 years ago and am certainly rusty, but thought it would be fun to simulate he effect two spheres have when they collide. Their are two types of collision; a perfectly elastic collision where there is no lose in kinetic energy and an inelastic collision where some or all of the kinetic energy is converted into internal energy.&nbsp;&nbsp; In the example below I try to demonstrate both types of collision along with a form of inelastic collision I call magnetic where upon collision energy is transferred in the direction of the collision and the sphere attaches itself to the object it is colliding with.
<p><iframe src="/wp-content/uploads/2008/05/SphericalCollision/default.html" width="450" height="450"></iframe></p>
<p>I am pretty certain I am taking some liberties with accuracy of each collision, but nonetheless one can see the effect two spheres have on momentum.&nbsp; Interestingly, if you allow the demo to run long enough most if not all of the balls will stop colliding. The first thing I needed to do to create my sample was to create a UserControl that would represent my sphere. Within this control I created a series of properties and two public Method: &#8220;Move()&#8221; and &#8220;Collision()&#8221;. Since each sphere will move through my container the same way, I can encapsulate this logic within the control itself. Here is that code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">public void Move(Rect bounds)
{
    //add the current vector to each X/Y 
    this.X += this.VX;
    this.Y += this.VY;
&nbsp;
    //check to see if this sphere has collided with an adjacent wall
    //if so, then reverse its vector.  Since my bounding box is definable 
    //pass in a Rect struct
&nbsp;
    //check the left and the right of the bound box
    if (this.X &amp;lt; bounds.X &amp;amp;&amp;amp; this.VX &amp;lt; 0)
        this.VX = -this.VX;
&nbsp;
    if(this.X &amp;gt; (bounds.Right-this.Distance) &amp;amp;&amp;amp; this.VX &amp;gt; 0)
        this.VX = -this.VX;
&nbsp;
    //check the top and the bottom
    if (this.Y &amp;lt; bounds.Y &amp;amp;&amp;amp; this.VY &amp;lt; 0)
        this.VY = -this.VY;
&nbsp;
    if(this.Y &amp;gt; (bounds.Bottom-this.Distance) &amp;amp;&amp;amp; this.VY &amp;gt; 0)
        this.VY = -this.VY;
&nbsp;
    //move this sphere to its new X,Y position
    _translate.X = this.X;
    _translate.Y = this.Y;
}</pre></td></tr></table></div>

<p>Since my container floats in the center of my Page.xaml I use a &#8220;Rect&#8221; struct to hold the X,Y, Width and Height of the UIElement that that will confine the spheres. I pass this &#8220;Rect&#8221; as an argument. Depending on the surface that the object is colliding with, I move the sphere and reverse the vector by either adding or subtracting itself from VX or VY. In addition to determining how itself moves, the sphere I also determines the effect of a collision. This method is pretty big, but is broken down into four sections. The first determines the time in which the two spheres collide where is the remaining determine the effect of each type of collision.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">public bool Collision(Sphere s)
{
    // find the time when the two spheres really collide with each other.
    double dx = (this.X + this._radius) - (s.X + s.Radius);
    double dy = (this.Y + this._radius) - (s.Y + s.Radius);
&nbsp;
    //calculate the distance between two balls 
    double distance = dx * dx + dy * dy;
    double distanceSqrt = Math.Sqrt(distance);
&nbsp;
    double dvx = this.VX - s.VX;
    double dvy = this.VY - s.VY;
&nbsp;
    if (distanceSqrt &amp;gt; (this._radius + s.Radius))
        return false;
    //There are two basic kinds of collisions, elastic and inelastic:
    //if an elastic collision occurs send both spheres rebounding backwards
    //with no loss in total kinetic energy.
&nbsp;
    //Note: since both of our spheres have the same mass the only way to determine 
    //which type of collision will occur is to look at velocity.
    double collision = 0.0;
    if (this.CollisionType == CollisionTypes.Elastic || 
	s.CollisionType == CollisionTypes.Elastic)
    {
        collision = dvx * dx + dvy * dy;
        if (collision &amp;gt; 0)
            return false;
&nbsp;
        collision /= distance;
&nbsp;
        double deltaVX = dx * collision;
        double deltaVY = dy * collision;
&nbsp;
        //deflect this sphere
        this._vx -= deltaVX;
        this._vy -= deltaVY;
        //deflect the sphere that was part of the collision
        s.VX += deltaVX;
        s.VY += deltaVY;
    }
    //if a partial inelastic collision occurs the spheres collide and some 
    //kinetic energy is lost...both masses decelerate
    else if(this.CollisionType == CollisionTypes.Inelastic || 
	s.CollisionType == CollisionTypes.Inelastic)
    {
        collision = dvx * dx + dvy * dy;
        if (collision &amp;gt; 0)
            return false;
&nbsp;
        collision /= distance*2;
&nbsp;
        double deltaVX = dx * collision;
        double deltaVY = dy * collision;
&nbsp;
        //deflect this sphere
        this._vx -= deltaVX;
        this._vy -= deltaVY;
        //deflect the sphere that was part of the collision
        s.VX += deltaVX;
        s.VY += deltaVY;
    }
    //if a magnetic collision occurs we would have a perfectly inelastic collision
    else if (this.CollisionType == CollisionTypes.Magnetic &amp;amp;&amp;amp; 
	s.CollisionType == CollisionTypes.Magnetic)
    {
        //the sphere causing the collision will continue its forward momentum 
        //attaching itself to the adjacent sphere
        s.VX = this.VX;
        s.VY = this.VY;
    }
    return true;
}</pre></td></tr></table></div>

<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/SphericalCollision.zip');" href="/wp-content/uploads/2008/05/SphericalCollision/SphericalCollision.zip">SphericalCollision.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/05/spherical-collisions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight Flipping Tiles Animation</title>
		<link>http://joel.neubeck.net/2008/05/silverlight-flipping-tiles-animation/</link>
		<comments>http://joel.neubeck.net/2008/05/silverlight-flipping-tiles-animation/#comments</comments>
		<pubDate>Fri, 16 May 2008 06:36:30 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[3D Flip]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[DispatcherTimer]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[Tiles]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/05/silverlight-flipping-tiles-animation/</guid>
		<description><![CDATA[Back a few weeks ago I posted an example of how to create a 3D flip animation similar to the effect seen on an iPhone. Today I will build upon that procedural animation and simulate the flipping tile affect seen in the iTunes album art screen saver, available on a Mac. In my example I [...]]]></description>
			<content:encoded><![CDATA[<p>Back a few weeks ago I posted an example of how to create a <a href="http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/">3D flip animation</a> similar to the effect seen on an iPhone. Today I will build upon that procedural animation and simulate the flipping tile affect seen in the iTunes album art screen saver, available on a Mac.
<p><iframe src="/wp-content/uploads/2008/05/LeopardSreenSaver/default.html" width="400" height="400"></iframe></p>
<p>In my example I have a total of 16 random tiles displayed from a collection of 42 different images. Any image not currently displayed is available to be randomly selected to replace an existing tile.&nbsp; Here is how I achieve the effect.&nbsp; </p>
<p>The project is comprised of a &#8220;Tile&#8221; UserControl , a class called &#8220;Media&#8221; and two generic lists (one to store references to the 16 tiles and one to store all 42 URI to the images).&nbsp; The first step is to fill my page.xaml grid with 16 tiles.&nbsp;&nbsp; Here is a snip of the code used to fill the grid.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">private void BuildCollection()
{
    int row = -1;
    int col = 0;
    for (int i = 0; i &amp;lt; 42; i++)
    {
        Uri imageUri = new Uri(string.Format(&quot;Images/{0}.png&quot;, 
		(i+1).ToString()), UriKind.Relative);
        if (i &amp;lt;= 16)
        {
            Tile tile = new Tile();
            Media media =  new Media(imageUri, true);
            tile.Media = media;
&nbsp;
            if (col % 4 == 0)
            {
                row++;
                col = 0;
            }
            tile.SetValue(Grid.ColumnProperty, col.ToString());
            tile.SetValue(Grid.RowProperty, row.ToString());
            this.LayoutRoot.Children.Add(tile);
&nbsp;
            col++;
            _tiles.Add(tile);
            _images.Add(media);
&nbsp;
        }
        else
            _images.Add(new Media(imageUri, false));
    }
}</pre></td></tr></table></div>

<p>For those of you just getting familiar with the &#8220;Grid&#8221; control you might not be aware that it supports implicitly specifying columns and rows. In this example I leverage this to ensure my tiles form a nice 4&#215;4 grid.&nbsp;&nbsp; </p>
<p>As you can see from the code, I have chosen to store only the URI to the image and not store the image itself. I had some difficulty storing a &#8220;BitmapImage&#8221; object in my collection and retrieving it consistently when I was ready to flip a tile. The URI seems less efficient, was reliable. </p>
<p>Now that I have built up my grid and two collections, I can use a DispacherTimer to randomly select a tile and randomly select an image to be used as the backside of the flip. He is how that code looks. </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">void _timer_Tick(object sender, EventArgs e)
{
    System.Random RandNum = new System.Random();
    int randomTile = RandNum.Next(16);
&nbsp;
    bool match = false;
    while(!match)
    {
        int randomImage = RandNum.Next(42);
        if(!_images[randomImage].Displayed)
        {
            _images[randomImage].Displayed = true;
            _tiles[randomTile].Media.Displayed = false;
            _tiles[randomTile].Flip(_images[randomImage]);
            match=true;
            break;
        }
    }
}</pre></td></tr></table></div>

<p>As you can see I am using a boolean property in the &#8220;Media&#8221; object to determine if an image is already displayed. The second level of randomization is there to help ensures that I am giving each image equal chance of getting displayed. </p>
<p>If one were to examine the &#8220;Tile&#8221; UserControl, it looks almost exactly like the code I created for the 3D flip animation example. In&nbsp; this situation instead of firing the flip based on a button click, I use the followings public method called from my main page.xaml DispatcherTimer tick. </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">public void Flip(Media media)
{
    this.Media = media;
&nbsp;
    if (_Front)
    {
        this.ImageBack.Source = new BitmapImage(_Media.ImageUri);
        _sb.Pause();
        _sb.AutoReverse = false;
        _sb.Begin();
        _Front = false;
    }
    else
    {
        this.ImageFront.Source = new BitmapImage(_Media.ImageUri);
        _sb.Pause();
        _sb.AutoReverse = true;
        _sb.Seek(_tsLastFrame);
        _sb.Resume();
&nbsp;
        _Front = true;
    }
}</pre></td></tr></table></div>

<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/LeopardSreenSaver.zip');" href="/wp-content/uploads/2008/05/LeopardSreenSaver/LeopardSreenSaver.zip">LeopardSreenSaver.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/05/silverlight-flipping-tiles-animation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
