|
namespace Frogger
{
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Threading;
public class Effects : ContentControl
{
private static BitmapImage[] explosionImages = new BitmapImage[] {
new BitmapImage(new Uri("media/explosion1.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion2.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion3.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion4.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion5.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion6.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion7.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion8.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion9.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion10.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion11.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion12.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion13.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion14.png", UriKind.RelativeOrAbsolute)),
new BitmapImage(new Uri("media/explosion15.png", UriKind.RelativeOrAbsolute))
};
private int curExplosionImage = 0;
private Image explosionImage = new Image();
private Canvas _canvas;
public EventHandler ExplosionEventHandler;
public event EventHandler ExplosionEnded;
public Effects( Canvas c, double left, double top)
{
explosionImage.Source = explosionImages[curExplosionImage];
this.Content = explosionImage;
this._canvas = c;
_canvas.Children.Add(this);
Canvas.SetLeft(this, left);
Canvas.SetTop(this, top);
DispatcherTimer t = new DispatcherTimer();
t.Interval = TimeSpan.FromMilliseconds(50);
t.Tick += new EventHandler(t_Tick);
t.Start();
}
void t_Tick(object sender, EventArgs e) {
if( curExplosionImage == explosionImages.Length )
{
_canvas.Children.Remove(explosionImage);
if (this.ExplosionEnded != null)
this.ExplosionEnded(sender,e);
}
else
{
explosionImage.Source = explosionImages[curExplosionImage];
curExplosionImage++;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Michael is the co-founder and master consultant for Concepts2Code, a software consulting company based in Buffalo, New York. He's been programming since the early 1990's. His vast programming experience includes VB, Delphi, C#, ASP, ASP.NET, Ruby on Rails, Coldfusion and PHP. Michael also is a Microsoft Certified Application Developer and a Certified Technology Specialist for SQL Server.
Visit his
blog.