private static void OnPlaysRemainingChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { SpritesheetImage self = o as SpritesheetImage; if (!self.timer.IsEnabled && (self.PlaysRemaining > 0 || self.LoopForever)) { self.timer.Start(); } else if (self.timer.IsEnabled && self.LoopForever == false && self.PlaysRemaining == 0) { self.timer.Stop(); } }
private static void OnFrameRateChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { SpritesheetImage self = o as SpritesheetImage; if (self != null) { if (e.NewValue is double && (double)e.NewValue > 0) { self.timer.Interval = TimeSpan.FromMilliseconds(1000 / (double)e.NewValue); } else { self.timer.Interval = TimeSpan.FromMilliseconds(Default_FrameRate); } } }
private void PlayerUserControl_Loaded(object sender, RoutedEventArgs e) { playerTile = new SpritesheetImage() { Source = facingRightImage, FrameMaxX = 5, FrameMaxY = 2, FrameRate = 30, Width = 64, Height = 64, PlaysRemaining = 10, LoopForever = true }; playerTile.AnimationComplete += (o, s) => { myCanvas.Children.Remove(playerTile); }; myCanvas.Children.Add(playerTile); }