<?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; TimerTrigger</title>
	<atom:link href="http://www.shazaml.com/archives/tag/timertrigger/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>Hidden Object: Episode 14 – Shake it up</title>
		<link>http://www.shazaml.com/archives/hidden-object-episode-14</link>
		<comments>http://www.shazaml.com/archives/hidden-object-episode-14#comments</comments>
		<pubDate>Wed, 25 Nov 2009 13:05:17 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Hidden Object Game]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[ControlStoryboardAction]]></category>
		<category><![CDATA[EventTrigger]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[GlobalCounterMaxReachedTrigger]]></category>
		<category><![CDATA[IncrementGlobalCounterAction]]></category>
		<category><![CDATA[SetGlobalCounterAction]]></category>
		<category><![CDATA[Storyboard]]></category>
		<category><![CDATA[TimerTrigger]]></category>
		<category><![CDATA[Trigger]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=385</guid>
		<description><![CDATA[If the player clicks too many times within a 5 second time frame trying to find an item, play the shake animation.]]></description>
			<content:encoded><![CDATA[<p>So far in the game, we have particles when an item is clicked, a hint to show the location of an unfound item, but what should we do if the player goes berserk and wildly clicks all over the place in hopes of finding a difficult-to-find item? In this 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 will add an earthquake effect if the player clicks too many times in a 5 second interval.</p>
<p>Let&#8217;s first start with the shake effect.  The magnifierCanvas Canvas contains the background image and all Paths for each clickable item. We will create a new storyboard called ShakeStoryboard that will animate the Left property of the Canvas:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec1.png" alt="" /></p>
<p> </p>
<p>Each of the 4 key frames set the Left property to a different value as shown in the storyboard XAML:</p>
<pre class="brush: xml; gutter: false;">
&lt;Storyboard x:Name=&quot;ShakeStoryboard&quot; RepeatBehavior=&quot;5x&quot; AutoReverse=&quot;False&quot; SpeedRatio=&quot;5&quot;&gt;
    &lt;DoubleAnimationUsingKeyFrames BeginTime=&quot;00:00:00&quot;
        Storyboard.TargetName=&quot;magnifierCanvas&quot;
        Storyboard.TargetProperty=&quot;(Canvas.Left)&quot;&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00&quot; Value=&quot;0&quot;/&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00.2000000&quot; Value=&quot;-10&quot;/&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00.4000000&quot; Value=&quot;10&quot;/&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00.6000000&quot; Value=&quot;0&quot;/&gt;
    &lt;/DoubleAnimationUsingKeyFrames&gt;
&lt;/Storyboard&gt;
</pre>
<p> </p>
<p>The Storyboard has the RepeatBehavior property set to repeat 5 times and the SpeedRatio property set to speed up the animation.</p>
<p>If the player clicks on the background image 10 times within a 5 second interval, then the ShakeStoryboard will play. To accomplish this we need three SetGlobalCounterAction instances and one ControlStoryboardAction added to the UserControl:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec2.png" alt="" /></p>
<p>The first SetGlobalCounterAction sets the values for the TooManyClicks counter when the UserControl loads:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec3.png" alt="" /></p>
<p> </p>
<p>The ControlStoryboardAction plays the ShakeStoryboard when the GlobalCounterMaxReachedTrigger is fired for the TooManyClicks key which we set previously to 10.</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec4.png" alt="" /></p>
<p>When the counter reaches 10 we need to set it back to zero which is what the second SetGlobalCounterAction does:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec5.png" alt="" /></p>
<p>The final SetGlobalCounterAction uses the TimerTrigger to reset the counter every 5 seconds:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec6.png" alt="" /></p>
<p> </p>
<p>The only thing left to do is add the IncrementGlobalCounterAction to the background image to increment the counter by 1:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec7.png" alt="" /></p>
<p> </p>
<p>So with 5 Action instances, 3 Trigger types, 1 Storyboard, and 0 lines of code we were able to quickly add this feature to the game.</p>
<p><a href="http://www.shazaml.com/downloads/ClutteredCubeSource14.zip"><img class="alignnone size-full wp-image-319" title="Zip" src="http://www.shazaml.com/wp-content/uploads/2009/10/Zip.png" alt="Zip" width="93" height="96" /> Source Code</a></p>
<p><a href="http://www.shazaml.com/hidden-object-game-episode-14-demo"><img class="alignnone size-full wp-image-320" title="silverlight" src="http://www.shazaml.com/wp-content/uploads/2009/10/silverlight.png" alt="silverlight" width="93" height="96" /> Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/hidden-object-episode-14/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
