<?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>SHAZAML! &#187; ContinuousPlayMediaBehavior</title>
	<atom:link href="http://www.shazaml.com/archives/tag/continuousplaymediabehavior/feed" rel="self" type="application/rss+xml" />
	<link>http://www.shazaml.com</link>
	<description>The Blog for Design &#38; Development Superheroes</description>
	<lastBuildDate>Wed, 28 Jul 2010 21:02:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Video: Creating a Silverlight 3 Casual Game using Blend 3 and Triggers, Actions, and Behaviors</title>
		<link>http://www.shazaml.com/archives/video-silverlight-casual-game</link>
		<comments>http://www.shazaml.com/archives/video-silverlight-casual-game#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:19:11 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Hidden Object Game]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[Behavior]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[ChangePropertyAction]]></category>
		<category><![CDATA[ContinuousPlayMediaBehavior]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[GlobalCounterMinReachedTrigger]]></category>
		<category><![CDATA[GoToStateAction]]></category>
		<category><![CDATA[IncrementGlobalCounterAction]]></category>
		<category><![CDATA[InvokeCommandAction]]></category>
		<category><![CDATA[MagnifierOverBehavior]]></category>
		<category><![CDATA[MouseCursorBehavior]]></category>
		<category><![CDATA[ParticlesBehavior]]></category>
		<category><![CDATA[PlaySoundAction]]></category>
		<category><![CDATA[RemoveElementAction]]></category>
		<category><![CDATA[SetGlobalCounterAction]]></category>
		<category><![CDATA[SetInteractionPropertyAction]]></category>
		<category><![CDATA[ShowGlobalCounterBehavior]]></category>
		<category><![CDATA[Trigger]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[Visual State Manager]]></category>
		<category><![CDATA[VSM]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=333</guid>
		<description><![CDATA[Video presentation from Desert Code Camp 2009 - Silverlight 3 Casual Game]]></description>
			<content:encoded><![CDATA[<p>On Saturday, November 7, 2009 at 9:00am I presented at the Desert Code Camp in Phoenix, AZ. The topic of my presentation was Silverlight casual game development. In less than an hour I demonstrated how to use triggers, actions, and behaviors in Blend 3 to create a hidden object game. Because all code was contained in the TABs (Triggers, Actions, and Behaviors) there was no code behind for the main UserControl.</p>
<p>Here is a link to the <a title="Video - Creating a Silverlight 3 Casual Game using Blend 3 and Triggers, Actions, and Behaviors" href="http://www.shazaml.com/downloads/DesertCodeCamp2009-Silverlight3CasualGame.wmv">presentation video</a> in WMV format.</p>
<p>If you like you can see <a href="http://www.shazaml.com/archives/creating-a-hidden-object-game-in-silverlight-3">all the episodes</a> and follow along with the tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/video-silverlight-casual-game/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
<enclosure url="http://www.shazaml.com/downloads/DesertCodeCamp2009-Silverlight3CasualGame.wmv" length="63294285" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>Hidden Object: Episode 8 – Loop Game Music with a Behavior</title>
		<link>http://www.shazaml.com/archives/hidden-object-episode-8</link>
		<comments>http://www.shazaml.com/archives/hidden-object-episode-8#comments</comments>
		<pubDate>Mon, 28 Sep 2009 13:24:58 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Hidden Object Game]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Behavior]]></category>
		<category><![CDATA[ContinuousPlayMediaBehavior]]></category>
		<category><![CDATA[games]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=207</guid>
		<description><![CDATA[Using a custom behavior we are able to continuously loop the background music.]]></description>
			<content:encoded><![CDATA[<p>In the last episode of <a href="http://www.shazaml.com/archives/creating-a-hidden-object-game-in-silverlight-3">Creating a Hidden Object Game is Silverlight 3</a> we finished off the magnifier feature. Now it is time to add some background music to the game and have it continually play.</p>
<p>First off, we need to find some appropriate music. I did a search for royalty-free &amp; public domain music and came across a <a href="http://derekaudette.ottawaarts.com/music.php">site by Derek R. Audette</a> that contained such music. On the site, I found a piece of music called &#8220;Combustible Coffee Pot&#8221; written &amp; performed by Derek R. Audette &#8211; ©MMV(Socan). Derek&#8217;s own description of the music is:</p>
<blockquote><p>&#8220;Out of control drum fills, singing string sections and odd, tense, electronic pads make up this bizarre composition. Created to add a mood of intrigue to an independent film produced in 2005.&#8221;</p></blockquote>
<p>Download the mp3 file and add it to the Audio folder.</p>
<p>In order to use the music in our game, we need to add a MediaElement control to LayoutRoot:</p>
<pre class="brush: csharp; gutter: false;">
&lt;MediaElement x:Name=&quot;musicElement&quot;
    Source=&quot;/Audio/Combustible_Coffee_Pot.mp3&quot;
    MediaEnded=&quot;musicElement_MediaEnded&quot;/&gt;
</pre>
<p>To get the continuous loop, we need to handle the MediaEnded event which sets the media position back to 0 and plays it again:</p>
<pre class="brush: csharp; gutter: false;">
private void musicElement_MediaEnded(object sender, System.Windows.RoutedEventArgs e)
{
    musicElement.Position = new TimeSpan(0);
    musicElement.Play();
}
</pre>
<p>But as developers, we don&#8217;t want to make our designers go into code behind and enter C# code. Since Silverlight doesn&#8217;t support continuously lookping media, we are going to package this functionality into a custom behavior.</p>
<p>Create a folder under Interactivity called ContinuousMediaPlayBehavior and create new class based on the Behavior template by the same name. All we are going to do is attach an event handler to the MediaEnded event in the OnAttached method and remove the handler in the OnDetaching method. To get the AssociatedObject property to be strongly typed to a MediaElement and thus allow this behavior to only be attached to the MediaElement type we change the behavior so it is typed to MediaElement. When the MediaEnded event is fired, we set the position of the media back to 0 and replay it:</p>
<pre class="brush: csharp; gutter: false;">
public class ContinuousPlayMediaBehavior : Behavior&lt;MediaElement&gt;
{
    public ContinuousPlayMediaBehavior() {}

    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.MediaEnded += AssociatedObject_MediaEnded;
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.MediaEnded -= AssociatedObject_MediaEnded;
    }

    void  AssociatedObject_MediaEnded(object sender, RoutedEventArgs e)
    {
        AssociatedObject.Position = new TimeSpan(0);
        AssociatedObject.Play();
    }
}
</pre>
<p>This is what the XAML looks like for this:</p>
<pre class="brush: xml; gutter: false;">
&lt;MediaElement x:Name=&quot;musicMediaElement&quot; Source=&quot;/Audio/Combustible_Coffee_Pot.mp3&quot;&gt;
    &lt;i:Interaction.Behaviors&gt;
        &lt;local:ContinuousPlayMediaBehavior/&gt;
    &lt;/i:Interaction.Behaviors&gt;
&lt;/MediaElement&gt;
</pre>
<p>In the <a href="http://www.shazaml.com/archives/hidden-object-episode-9">next episode</a>, we will continue to work on the UI by adding various screens including one to control the volume of the background music we just added.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/hidden-object-episode-8/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
