23 October 2007

Silverlight: Keep it simple stupid.

A while back I posted about how I used our AJAX Control Toolkit to animate with Silverlight. I stated that the end reason for this approach was simply due to lack of animation capabilities within Silverlight 1.0.

Michael Scherotter being the brilliant Silverlight coder, decided to prove that theory wrong (heh - not so much, probably more to acid test my b.s factor). He came back with an approach that was simple and yet humiliating (for me) at the same time (I'm so embarrassed).

 1:  void Handle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseEventArgs e)
 2:  {
 3:  switch (m_state)
 4:  {
 5:  case ShadeState.down:
 6:  m_state = ShadeState.goingUp;
 7:  UpHandleStart.Value = m_upHandleStart;
 8:  UpShadeStart.Value = m_upShadeStart;
 9:  Up.SpeedRatio = 1.0;
 10:  Up.Seek(new TimeSpan(0));
 11:  Up.Begin();
 12:  break;
 13:  
 14:  case ShadeState.goingDown:
 15:  m_state = ShadeState.goingUp;
 16:  Down.Pause();
 17:  UpHandleStart.Value = HandleTranslation.Y;
 18:  UpShadeStart.Value = Shade.Height;
 19:  Up.SpeedRatio = 2.0;
 20:  Up.Begin();
 21:  break;
 22:  
 23:  case ShadeState.goingUp:
 24:  m_state = ShadeState.goingDown;
 25:  Up.Pause();
 26:  DownHandleStart.Value = HandleTranslation.Y;
 27:  DownShadeStart.Value = Shade.Height;
 28:  Down.SpeedRatio = 2.0;
 29:  Down.Begin();
 30:  break;
 31:  
 32:  case ShadeState.up:
 33:  m_state = ShadeState.goingDown;
 34:  DownHandleStart.Value = m_downHandleStart;
 35:  DownShadeStart.Value = m_downShadeStart;
 36:  Down.Seek(new TimeSpan(0));
 37:  Down.SpeedRatio = 1.0;
 38:  Down.Begin();
 39:  break;
 40:  }

Essentially what he's done is wire up the animation(s) to mouse events (i.e. when the user clicks, make sure you fire this methods). He's then put together 4 states so to speak and based on where things in time are at, he adjusts and forces the animation to react accordingly.

Simple!

This problem reminds me of a game I once wrote in Flash. It was a XMAS game where Santa would kick presents into chimneys based on where the power bar was at (i.e. user needs to guess the right amount of power). I wrote the game in such a way that it used gravity, physics etc  and took forever. It took a Flash Designer on my team to show me that all that was need was a few motion paths and when the power bar got within certain ranges, it would fire off the right animation path (ie 50-60% meant gotoAndPlay(3)).

Amazing how one can write 115 lines of code for "Hello World" when all you need is 2 lines.

Filed under: ,
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# MSDN Blog Postings » Silverlight: Keep it simple stupid. said:

PingBack from http://msdnrss.thecoderblogs.com/2007/10/22/silverlight-keep-it-simple-stupid/

22 October 07 at 10:33 AM
# WynApse said:

Silverlight Cream for October 23, 2007 -- #110

23 October 07 at 9:21 AM
# Jeanne said:

All nt ACTIVE X display "Damaged" Should they be deleted or what?

10 December 07 at 10:20 AM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

About scbarnes

Scott Barnes currently is a Rich Platform Product Manager (WPF & Silverlight). He has been working with Adobe/Macromedia technology for the past 10 years with a main focus specifically on Internet Applications (aka. RIA, Rich Client Technology etc).

Scott first started out as a graphic designer in the late 90’s and over the years developed a passion for programmatic art (Designer + Developer mind). He recently has branched out further into 3D modelling and animation making full use of both his designer + developer mindset.

"..The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man..." - George Bernard Shaw
Page view tracker