SpriteHand
Module Border
  Timers in Silverlight
Module Border
Location: BlogsAndy's Blog    
Posted by: host 5/5/2007 10:36 PM

I was surprised to see that custom timers (like System.Timers.Timer) are not yet supported in Silverlight 1.1 Alpha. These would be great for creating "casual games" such as those that made Flash so popular.

Luckily, I came across this post by Joe Stegman that shows a workaround by using an Animation Timer:

First set up an Animation Timer in your xaml...

<Canvas.Resources>
  <
Storyboard x:Name="timer">
    <
DoubleAnimation Duration="00:00:0.02" />
  </
Storyboard>
</
Canvas.Resources>

Then you can add an "tick" event handler and start up the timer..

timer.Completed += new EventHandler(timer_Completed);
timer.Begin();

And finally, make sure you restart the timer in the timer_Completed event.

void timer_Completed(object sender, EventArgs e)
{
   // ... do per tick stuff here...

   // restart the timer
  
timer.Begin();
}

Permalink |  Trackback

Comments (4)   Add Comment
Re: Timers in Silverlight    By Anonymous on 11/28/2010 11:48 PM
This approach doe NOT work in Silverlight 4
It throws error: Animation target not specified.

Re: Timers in Silverlight    By Anonymous on 1/21/2011 3:24 AM
For me too

Re: Timers in Silverlight 4 FIX    By Anonymous on 2/9/2011 1:03 PM










Re: Timers in Silverlight 4 FIX    By Anonymous on 2/9/2011 1:06 PM
Storyboard x:Name="timer1" Storyboard.TargetName="_timer" Storyboard.TargetProperty="(UIElement.Opacity)"
DoubleAnimation Duration="00:00:2"

Rectangle x:Name="_timer" Opacity="0"


Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border


PHYSAMAJIG
This Windows app was created using Physics Helper XAML, and the Farseer Physics Engine.
DOWNLOAD

MORE INFO



TALKING RAGDOLL
This Windows Phone app was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight , the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2014 andy.beaulieu.com - Login