<?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 Buzz &#187; Silverlight 2 tutorials</title>
	<atom:link href="http://www.silverlightbuzz.com/category/silverlight-2-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.silverlightbuzz.com</link>
	<description>Gavin Wignall Blogs about Silverlight tutorials and examples</description>
	<lastBuildDate>Wed, 23 Jun 2010 08:57:16 +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>Using the mouse position to control movement</title>
		<link>http://www.silverlightbuzz.com/2009/05/27/using-the-mouse-position-to-control-movement/</link>
		<comments>http://www.silverlightbuzz.com/2009/05/27/using-the-mouse-position-to-control-movement/#comments</comments>
		<pubDate>Wed, 27 May 2009 15:30:40 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=218</guid>
		<description><![CDATA[In the below example we take the co-ordinates of the mouse and use that data to control the position of...]]></description>
			<content:encoded><![CDATA[<p>In the below example we take the co-ordinates of the mouse and use that data to control the position of another item. This can be used for sliders, menus, carousels etc;</p>
<p>I have written the code to adapt to the size of the scrollable area, you can see this by clicking on the &#8216;+&#8217; and &#8216;-&#8217; buttons. These will add / remove the items inside the scrollable area. If you remove enough items so that the area taken up is less than that of the screen, the items are positioned in the middle.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/menuSlider/menuSlider.html" frameborder="0" style="height:200px;width:490px;">Please upgrade your browser</iframe>
</div>
<p/>
To carry out this effect I need to keep track of the mouse position, the width of the screen and the width of the Stack panel containing the items. Each of these values need to be updated when ever they are changed.</p>
<p>I then position the movable area based on the following equations;</p>
<p><em><span style="color: #339966;">Where:</span></em><br />
a = Mouse X position<br />
b = Width of Screen area<br />
c = Width of area to be moved<br />
<em><span style="color: #339966;"> if movable area is bigger than screen area:</span></em><br />
moveable area X position = (a/b)*(b-c)<br />
<em><span style="color: #339966;"> if moveable area is smaller than screen area:</span></em><br />
moveable area X position = (b-c)/2</p>
<p>This equation is run every time a frame is rendered.</p>
<h2><span style="font-weight: normal;">T</span>he User Experience bit</h2>
<p>It is an important interaction that when working with scrolling content like this, especially when the content is a menu, to make sure that the direction of new content approaches the movement of the mouse.</p>
<h2><span style="font-weight: normal;">G</span>et the code</h2>
<p>As always you can download the example files <a href="http://www.silverlightbuzz.com/examples/MenuSlider.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/05/27/using-the-mouse-position-to-control-movement/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Zoom in and out using the Mouse wheel in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/05/19/zoom-in-and-out-using-the-mouse-wheel-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/05/19/zoom-in-and-out-using-the-mouse-wheel-in-silverlight/#comments</comments>
		<pubDate>Tue, 19 May 2009 13:01:58 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Mouse Wheel]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Zoom]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=203</guid>
		<description><![CDATA[Below is an example showing a simple zoom in / out interaction controlled via the mouse wheel, a slider and...]]></description>
			<content:encoded><![CDATA[<address>Below is an example showing a simple zoom in / out interaction controlled via the mouse wheel, a slider and some buttons.<span style="color: #ff0000;"> </span><span style="color: #808080;"><span style="color: #ff0000;">*Please note, mouse wheel functionality not currently working in the <strong>Google Chrome browser</strong>. Due to the Silverlight example being displayed within an iFrame you will experience issues with scrolling, to open the example in a new window click </span><a title="Mouse Wheel Scroll" href="http://www.silverlightbuzz.com/silverlightProjects/MouseWheelZoom/MouseWheelZoom.html" target="_blank"><span style="color: #ff0000;"><strong>here</strong></span></a><span style="color: #ff0000;">.</span></span></address>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/MouseWheelZoom/MouseWheelZoom.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br/>First off I add the following reference at the top of my C# file so that we can interact with the browser;</p>
<p><em><span style="color: #666699;">using System.Windows.Browser;</span></em></p>
<p>To then listen for the Mouse wheel interaction I set events in the browser using the following piece of C#;</p>
<p><em><span style="color: #666699;">HtmlPage.Window.AttachEvent(&#8220;DOMMouseScroll&#8221;, OnMouseWheel);<br />
HtmlPage.Window.AttachEvent(&#8220;onmousewheel&#8221;, OnMouseWheel);<br />
HtmlPage.Document.AttachEvent(&#8220;onmousewheel&#8221;, OnMouseWheel);</span></em></p>
<p>I can then check for a value to see if the mouse wheel is being moved forward or backward using the following Method;</p>
<p><em><span style="color: #666699;">private void OnMouseWheel(object sender, HtmlEventArgs args)<br />
{<br />
double mouseDelta = 0;<br />
ScriptObject e = args.EventObject;</span></em></p>
<p><em><span style="color: #666699;"><span style="color: #339966;"> // Mozilla and Safari</span><br />
if (e.GetProperty(&#8220;detail&#8221;) != null)<br />
{<br />
mouseDelta = ((double)e.GetProperty(&#8220;detail&#8221;));<br />
}<br />
<span style="color: #339966;"> // IE and Opera</span><br />
else if (e.GetProperty(&#8220;wheelDelta&#8221;) != null)<br />
mouseDelta = ((double)e.GetProperty(&#8220;wheelDelta&#8221;));<br />
mouseDelta = Math.Sign(mouseDelta);<br />
}</span></em></p>
<p>This now gives me a value in the form of &#8216;mouseDelta&#8217; which can be applied to what ever you want your interaction to be. In this case we are controlling the scale factor of a canvas.</p>
<p>To limit the scale factor I run a check to see if the scale value has gone under 1 or over 10 and if so reset the value to the minimum or maximum amount;</p>
<p><em><span style="color: #666699;">if (ScaleFactor.ScaleX &lt; 1)<br />
{<br />
ScaleFactor.ScaleX = 1;<br />
ScaleFactor.ScaleY = 1;<br />
}</span></em></p>
<p><em><span style="color: #666699;"> if (ScaleFactor.ScaleX &gt; 10)<br />
{<br />
ScaleFactor.ScaleX = 10;<br />
ScaleFactor.ScaleY = 10;<br />
}</span></em></p>
<p>I also check where the mouse cursor is and focus the zoom in / out on that position. I do this by storing the mouse co-ordinates everytime the user moves their mouse and then changing the &#8216;RenderTransformOrigin&#8217; value;</p>
<p><span style="color: #339966;">//get mouse co-ordinates</span><br />
<em><span style="color: #666699;"> void zoomArea_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
pt = e.GetPosition(zoomArea);<br />
}</span></em></p>
<p><span style="color: #339966;">//change the RenderTransformOrigin</span><span style="color: #666699;"><br />
</span><em><span style="color: #666699;"> zoomArea.RenderTransformOrigin = new Point(pt.X / zoomArea.Width, pt.Y / zoomArea.Height);</span></em></p>
<h2>Get the code</h2>
<p>You can download the above example <a href="http://www.silverlightbuzz.com/examples/PanAndZoom.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/05/19/zoom-in-and-out-using-the-mouse-wheel-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Rotation controlled direction using trigonometry and radians in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/03/29/rotation-controlled-direction-using-trigonometry-and-radians-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/29/rotation-controlled-direction-using-trigonometry-and-radians-in-silverlight/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 15:22:02 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverllight Games]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Radians]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[User Input]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=170</guid>
		<description><![CDATA[The below example shows an object being controlled by user input. To get the object to turn left or right...]]></description>
			<content:encoded><![CDATA[<p>The below example shows an object being controlled by user input. To get the object to turn left or right is a relatively simple procedure as seen below:</p>
<p><em>if (e.Key == Key.Left)<br />
{<br />
      </em><span style="color: #ff0000;"><strong><em>tankRotate.Angle -= 1;</em></strong></span><em><br />
}<br />
if (e.Key == Key.Right)<br />
{<br />
      </em><span style="color: #ff0000;"><strong><em>tankRotate.Angle += 1;</em></strong></span><em><br />
}</em><br />
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/RotationDirection/TestPage.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br />The above example turns the object by 1 degree left or 1 degree right, you can use any value to make the object turn faster or slower.</p>
<p>To get the object to move forward in the direction it is facing is going to require our old friend &#8216;Trig&#8217; to take center stage. We can use the following formulae to calculate how far to move our object by its X and Y co-ordinates:</p>
<p><strong><span style="color: #ff0000;"><span style="color: #000000;"><span style="font-weight: normal;">Move X by:</span></span> Math.Cos(Angle) * Speed</span></strong></p>
<p><strong><span style="color: #ff0000;"><span style="color: #000000;"><span style="font-weight: normal;">Move Y by:</span></span> Math.Sin(Angle) * Speed</span></strong></p>
<p>Where <span style="color: #ff0000;"><strong>Angle </strong></span>is in radians.</p>
<h2>Radians</h2>
<p>1 radian is equal to 57.29577 degrees of a full circle. So if our object is turned at an angle of 57.29577 degrees it is equal to 1 radian. To work out the value of our angle in radians we can use the following formula:</p>
<p><span style="color: #ff0000;"><strong><span style="color: #000000;"><span style="font-weight: normal;">Radians =</span></span> Angle / 360 * 2 * Pi</strong></span></p>
<h2>Working out how much to move our object</h2>
<p><span style="color: #ff0000;"><em><span style="color: #000000;">i.e. <span style="font-style: normal;">if our object is turned to <span style="color: #ff0000;">45 </span>degrees and our required movement speed is <span style="color: #ff0000;">2</span>.</span></span></em></span></p>
<p><span style="color: #ff0000;"><em><span style="color: #000000;"></span></em></span></p>
<p><span style="color: #ff0000;"><strong>X += Math.Cos(45 / 360 * 2 * 3.14159) * 2;</strong></span></p>
<p><span style="color: #ff0000;"><strong>Y += Math.Sin(45 / 360 * 2 * 3.14159) * 2;</strong></span></p>
<h2><span style="color: #000000;">Applying this formula to the C#</span></h2>
<p>So to return to the example at the begining of this post. I use the below calculations to work out how much to increase or decrease the X and Y positions of my object:</p>
<p><em>if (e.Key == Key.Up) </em></p>
<p><em>{</em></p>
<p><span style="color: #ff0000;"><strong><em>        tankMovement.X += Math.Cos(tankRotate.Angle / 360 * 2 * 3.14159) * 1;</em></strong></span></p>
<p><span style="color: #ff0000;"><strong><em>        tankMovement.Y += Math.Sin(tankRotate.Angle / 360 * 2 * 3.14159) * 1;</em></strong></span></p>
<p><em>}</em></p>
<h2>Get the code</h2>
<p>Feel free to grab the <a href="http://www.silverlightbuzz.com/examples/RotationControlledDirection.zip">code here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/29/rotation-controlled-direction-using-trigonometry-and-radians-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling an object using the Keydown function in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/03/25/controlling-an-object-using-the-keydown-function-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/25/controlling-an-object-using-the-keydown-function-in-silverlight/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 01:10:38 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverllight Games]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Collision]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[User Input]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=165</guid>
		<description><![CDATA[The below example shows an object being controlled by user input on a keyboard. I capture the &#8216;Keydown&#8216; event and...]]></description>
			<content:encoded><![CDATA[<p>The below example shows an object being controlled by user input on a keyboard. I capture the &#8216;<strong>Keydown</strong>&#8216; event and then check what keys are being pressed using a range of &#8216;<strong>if</strong>&#8216; statements.</p>
<p>Upon recognition of a key assigned to a direction, an increase (or decrease depending on direction) is made to a variable that is then applied to the the Helicopters &#8216;<strong>Canvas.setTop</strong>&#8216; or &#8216;<strong>Canvas.setLeft</strong>&#8216;.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/helicopter/TestPage.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br />This movement is then applied every frame using the &#8216;<strong>CompositionTarget.Rendering</strong>&#8216; event.</p>
<p>The &#8216;Space bar&#8217; or Numeric &#8217;5&#8242; key will level the Helicopter out and stop it moving in any direction. This is done by reducing or increasing the movement in all directions until all values equal zero.</p>
<p>I constantly repeat 2 storyboards to animate the helicopter blades and make visible/collapse one of 5 graphics to display the helicopter facing in the relevant direction that it is moving in. Finally I constantly run a calculation to tilt (RotateTransform) the helicopter in the direction it is moving and making it level when not moving.</p>
<p>To save the user from loosing sight of the helicopter in the above example I have put in a collision check to make sure the helicopter can not fly outside of the viewable area. If the user controls the helicopter to fly past any boundary then the helicopters movement in that direction will be reset to zero.</p>
<h2>Next steps</h2>
<p>I would like to add a winch that can be dropped down below the helicopter. The winch could then be made to pick objects up and drop them on command.</p>
<h2>Get the code</h2>
<p>Feel free to grab the code <a href="http://www.silverlightbuzz.com/examples/HeliGame.zip">here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/25/controlling-an-object-using-the-keydown-function-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building a paint application in Silverlight using the &#8216;Line&#8217; element</title>
		<link>http://www.silverlightbuzz.com/2009/03/15/building-a-paint-application-in-silverlight-using-the-line-element/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/15/building-a-paint-application-in-silverlight-using-the-line-element/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 22:46:10 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Colour palette]]></category>
		<category><![CDATA[Designers]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Drag]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Paint]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=152</guid>
		<description><![CDATA[The below example shows a simple paint application in Silverlight. You can select from 10 colours, change the brush size...]]></description>
			<content:encoded><![CDATA[<p>The below example shows a simple paint application in Silverlight. You can select from 10 colours, change the brush size and the opacity.</p>
<p>To get this effect I run some event handlers to check when the mouse is being pressed. While the mouse is pressed, every time the mouse is moved a new &#8216;Line&#8217; element is produced and plots the co-ordinates from the previous mouse position to the current position. This &#8216;Line&#8217; element is then styled up based on the selection from the colour palette and sliders. Finally I set <strong>Line1.StrokeStartLineCap = PenLineCap.Round; </strong>and <strong>Line1.StrokeEndLineCap = PenLineCap.Round; </strong>to ensure the joins between each &#8216;Line&#8217; element fits snugly.<br />
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/SilverlightPaint/TestPage.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br />
<h2>Possible improvements</h2>
<p>Firstly it would be nice to add a feature to erase paint &#8211; I haven&#8217;t spent much time thinking about how to do this yet as I&#8217;m sure it&#8217;s going to be quite tricky.</p>
<p>It would be quite easy to add tools to draw rectangles and circles and even reasonably easy to add a gradient tool to colour these up.</p>
<p>Text would be an interesting addition.</p>
<p>The ability to save your master piece to either return at a later point or export to an image would be cool.</p>
<h2>Get the code</h2>
<p>As always, feel free to grab the code <a href="http://www.silverlightbuzz.com/examples/Silverlight_Paint.zip">here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/15/building-a-paint-application-in-silverlight-using-the-line-element/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Collision testing on a free moving object in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/03/12/collision-testing-on-a-free-moving-object-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/12/collision-testing-on-a-free-moving-object-in-silverlight/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 21:17:25 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[Silverllight Games]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Collision]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Drag]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Gravity]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Shadow]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=149</guid>
		<description><![CDATA[The below example shows a dragable ball that when released will bounce around with a simulated gravity effect. There is...]]></description>
			<content:encoded><![CDATA[<p>The below example shows a dragable ball that when released will bounce around with a simulated gravity effect. There is also a box (&#8216;Move me&#8217;) that you can drag that the bouncy ball will bounce off / on.</p>
<p>In a previous post (<a href="http://www.silverlightbuzz.com/2009/03/11/silverlight-gravity-simulation-on-a-dragable-ball/">here</a>) I dabbled in making a dragable bouncy ball that simulated a gravity effect when released. I have taken that project and cleaned it up a bit to get rid of most of the bugs.<br />
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/BouncyBallCollisionTesting/Default.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br />I have also set up all of the controlling factors as variables so you can get in and play with the effects easier, see below for your &#8216;built in&#8217; options:</p>
<p><span style="color: #339966;"> //Declare the limits of where the ball can bounce</span><br />
<span style="color: #0000ff;"> private double </span>BounceBoundaryLeft = 10;<br />
<span style="color: #0000ff;"> private double</span> BounceBoundaryTop = 10;<br />
<span style="color: #0000ff;"> private double</span> BounceBoundaryRight = 490;<br />
<span style="color: #0000ff;"> private double</span> BounceBoundaryBottom = 390;<br />
<span style="color: #339966;"> //Set Margin for dragging the Ball around the edge of the screen</span><br />
<span style="color: #0000ff;"> private double</span> DragMargin = 30;<br />
<span style="color: #339966;"> //Declare Ball properties</span><br />
<span style="color: #0000ff;"> private double </span>BouncyBallWeight = 0.7;<br />
<span style="color: #0000ff;"> private double</span> BounceLevel = 0.8;<br />
<span style="color: #339966;"> // Declare Shadow properties</span><br />
<span style="color: #0000ff;"> private double </span>ShadowOffset = 10;<br />
<span style="color: #0000ff;"> private double</span> ShadowHeightLimit = 300;</p>
<h2>Get the code</h2>
<p>Feel free to grab the code <a href="http://www.silverlightbuzz.com/examples/BouncyBallCollisionTesting.zip">here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/12/collision-testing-on-a-free-moving-object-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Silverlight gravity simulation on a dragable ball</title>
		<link>http://www.silverlightbuzz.com/2009/03/11/silverlight-gravity-simulation-on-a-dragable-ball/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/11/silverlight-gravity-simulation-on-a-dragable-ball/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 00:28:45 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[Silverllight Games]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Collision]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Drag]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Gravity]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Shadow]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=142</guid>
		<description><![CDATA[So below is a first attempt on implementing gravity on a dragable object. There are a couple minor bugs still...]]></description>
			<content:encoded><![CDATA[<p>So below is a first attempt on implementing gravity on a dragable object. There are a couple minor bugs still but the core idea generally works.</p>
<p>Use the mouse to click and drag the ball, move the mouse and let go of the mouse button as you&#8217;re moving the mouse. The ball will pick up on the direction you were moving and continue in the same direction.<br />
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/BouncyBall1/Default.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br/>While the ball continues in this direction a force will pull the ball towards the ground, effectively trying to simulate gravity.</p>
<p>If the ball hits the ground the momentum built up by the ball will be reflected partially and rebound the ball back upwards.</p>
<p>If the ball hits the left, top or right boundary then the ball will be reflected partially and rebound in the opposite direction.</p>
<p>If the ball is dragged outside the of the boundaries of the Silverlight area then the ball will continue to move in the direction it was going in at the last point of contact, bouncing off the related boundary.</p>
<p>I have featured 2 Sliders to allow you to adjust the variables slightly to change the effect on the ball.</p>
<h2>Future Enhancements</h2>
<p>There are still a few bugs, every so often the ball will react a bit crazy &#8211; this is due to my coding no doubt, I would like to address this.</p>
<p>I would like to implement a dragable block that the ball would react and bounce off.</p>
<p>I would like to be able to have multiple balls on the stage with different properties that can additionally interact/bounce off each other</p>
<h2>Get the code</h2>
<p>As always you can grab the code <a href="http://www.silverlightbuzz.com/examples/BouncyBallTest.zip">here</a>, please pull it apart and enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/11/silverlight-gravity-simulation-on-a-dragable-ball/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Silverlight Rain Effect &#8211; Playing with Random</title>
		<link>http://www.silverlightbuzz.com/2009/03/07/silverlight-rain-effect-playing-with-random/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/07/silverlight-rain-effect-playing-with-random/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 19:19:11 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[User Input]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=135</guid>
		<description><![CDATA[Using the Random command in Silverlight we can simulate rain falling with out risking a repetitive effect. In the above...]]></description>
			<content:encoded><![CDATA[<p>Using the Random command in Silverlight we can simulate rain falling with out risking a repetitive effect. </p>
<p>In the above example a single control houses the rain drop graphic and its storyboard animating from the top of the screen to the bottom. I then use the Random command in Silverlight to decide where the rain drop will fall, what angle it will fall at and how deep (using scale) into the image it will appear to be.<br />
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/rain/Default.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br />The slider controls the amount of rain drops that fall per second. At the left end of the slider there will be 1 rain drop produced every 40th of a second, at the right end there will be 10 rain drops produced every 40th of a second. This is done using a &#8216;For&#8217; loop, the amount of loops being controlled by the slider.</p>
<h2>Possible enhancements</h2>
<p>A control/slider could be added to control the wind direction and speed.<br />
An effect placed on the background to simulate less light as rain fall increases.</p>
<h2>Get the code</h2>
<p>Feel free to grab the code <a href="http://www.silverlightbuzz.com/examples/rain.zip">here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/07/silverlight-rain-effect-playing-with-random/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silverlight Bugs v1 &#8211; Playing with Random</title>
		<link>http://www.silverlightbuzz.com/2009/03/05/silverlight-bugs-v1-playing-with-random/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/05/silverlight-bugs-v1-playing-with-random/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 19:37:29 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverllight Games]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Collision]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=124</guid>
		<description><![CDATA[Using the Random command in Silverlight we can give the impression that elements are thinking for themselves. By clicking the...]]></description>
			<content:encoded><![CDATA[<p>Using the Random command in Silverlight we can give the impression that elements are thinking for themselves. By clicking the &#8216;add a bug&#8217; button in the below example the Silverlight will create a new bug with a &#8216;bugLife&#8217; value of 100. After that everything else that happens is controlled by the Random command starting off with the colour of the bug and then the direction it faces, the speed it moves at and finally how long it is untill the bug makes a new set of decisions.<br />
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/Bugs1/TestPage.html" frameborder="0" style="height:340px;width:400px;">Please upgrade your browser</iframe>
</div><br />The bug will lose 1 point of life every time it makes a new decision and a further 4 points if it bumps into the wall (the edge of the screen). When the &#8216;bugLife&#8217; value reaches zero the bug will die and cease movement.</p>
<h2><strong>Future enhancements</strong></h2>
<p>I have already got additional values set up so that I can allow the user to customize each bug a little. For example you could give the bug extra life, tell it to make decisions quicker or speed it up. So I plan on making a popup/interface for the user to interact with these settings.</p>
<p>I also plan on adding a trait to each bug that will decide on how each bug will act when it comes in contact with another bug. For example 2 bugs could fight, run away from each other or reproduce and create more bugs. These new bugs would retain qualities from the 2 that produced them.</p>
<p>Finally I want to add the ability for the user to place food on the stage. This will attract bugs within a certain range and replenish their &#8216;bugLife&#8217; while the food lasts.</p>
<h2><strong>Get the code</strong></h2>
<p>Feel free to grab the code <a href="http://www.silverlightbuzz.com/examples/ticker.zip">here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/05/silverlight-bugs-v1-playing-with-random/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Using Easing to apply acceleration or inertia to an animation in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/02/19/using-easing-to-apply-acceleration-or-inertia-to-an-animation-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/02/19/using-easing-to-apply-acceleration-or-inertia-to-an-animation-in-silverlight/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 15:02:28 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight Blend Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[Collision]]></category>
		<category><![CDATA[Designers]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=110</guid>
		<description><![CDATA[You can download the example files to this article here. The below example shows three balls animating along the same...]]></description>
			<content:encoded><![CDATA[<p>You can download the example files to this article <a href="http://www.silverlightbuzz.com/examples/Bounce.zip">here</a>.</p>
<p>The below example shows three balls animating along the same distance over the same time.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/bounce/Default.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br /><strong>Ball 1</strong> is the most basic of animations going back and forth from A to B at a constant speed. Although this is a required function it often leaves animations a little lifeless and robotic.</p>
<p>The &#8216;easing&#8217; feature in Blend allows us to add acceleration or inertia to an animation. In other words, instead of a constant speed we can make an object speed up and slow down during its path while still taking the same time to reach its destination. This effect can really bring animations to life, mimicking how objects work in real life.</p>
<p><strong>Ball 2</strong> uses the &#8216;easing&#8217; feature to speed up the animation at the begining and slow down at the end each time the ball is moved. Notice how ball 1 still reaches its destination at the same time as ball 2 every time.</p>
<p>There are 2 ways of applying &#8216;easing&#8217; to your animation inside the Blend interface:</p>
<p><strong>Selecting a percentage for &#8216;easing in&#8217; and &#8216;easing out&#8217;</strong></p>
<p>Right click on a key frame and select either easing in or easing out. Choose a percentage from the list. In this method the Easing in relates to the journey to the keyframe where as easing out relates to the journey happening after the keyframe.</p>
<p><img class="alignnone" title="access easing by right clicking on the key frame" src="http://www.silverlightbuzz.com/images/bounce1.jpg" alt="" width="500" height="250" /></p>
<p><strong>Using the Easing graph</strong></p>
<p>Highlight a key frame (not at zero seconds) and go to the properties tab, the easing graph should now be displayed as below.</p>
<p><img class="alignnone" title="Access the easing graph through the Properties tab" src="http://www.silverlightbuzz.com/images/bounce2.jpg" alt="" width="295" height="423" /></p>
<p>Pull the yellow pin on the left bottom to adjust easing in and pull the yellow pin on the top right to adjust easing out. The easing graph allows you to fine tune your animation in more detail. The easing graph effects the keyframe slightly differently to the first method, the easing in and easing out changed on the graph are related to the animation space between the current selected key frame and the key frame before it.</p>
<p><strong>Ball 3</strong> only applies the &#8216;easing&#8217; feature at one of the 2 destinations mimicking a bouncing ball in real life. For the purpose of this example the ball never looses its energy through gravity so it will bounce for ever.</p>
<p>An additional scale animation has been placed at the moment ball 3 hits the pretend ground to mimick the ball being impacted and rebounding. This animation has been place on the grid containing the ball so that it can be easily run independantly to the bounce movement.</p>
<p><img class="alignnone" title="Adding a scale transform to fake impact" src="http://www.silverlightbuzz.com/images/bounce3.jpg" alt="" width="500" height="250" /></p>
<p><em><strong>And finally..</strong></em></p>
<p>This example loops forever because of a variable we can set in the XAML. Unfortunately the current version of Blend does not offer this function in the interface so you will have to switch to the XAML or Split view and find the Storyboard you want to loop. After the Storyboards x:Name place the following XAML.</p>
<p><span style="color: #ff0000;">RepeatBehavior</span>=&#8221;<span style="color: #0000ff;">Forever</span>&#8221;</p>
<p>See a screen shot here:</p>
<p><img class="alignnone" title="Edit the XAML to enable the storyboard to loop forever" src="http://www.silverlightbuzz.com/images/bounce4.jpg" alt="" width="500" height="50" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/02/19/using-easing-to-apply-acceleration-or-inertia-to-an-animation-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
