public MetroTile() { InitializeComponent(); TimeSpan d = TimeSpan.FromMilliseconds(200); Storyboard sb = new Storyboard() { Duration = d }; DoubleAnimation da = new DoubleAnimation() { Duration = d }; Storyboard.SetTarget(da, grr); Storyboard.SetTargetProperty(da, new PropertyPath(Grid.OpacityProperty)); bool cl = false; sb.Completed += delegate(object s, EventArgs e) { if (cl) { OnClick(); } }; grr.MouseLeftButtonUp += delegate(object s, System.Windows.Input.MouseButtonEventArgs e) { TimeSpan d1 = TimeSpan.FromMilliseconds(d.TotalMilliseconds / 3); TimeSpan d2 = TimeSpan.FromMilliseconds((d.TotalMilliseconds / 3) * 2); DoubleAnimation da1 = da.Clone(); da1.To = 1; da1.Duration = d1; DoubleAnimation da2 = da.Clone(); da2.To = 0; da2.BeginTime = d1; da2.Duration = d2; sb.Children.Clear(); sb.Children.Add(da1); sb.Children.Add(da2); sb.Begin(); cl = true; }; grr.MouseEnter += delegate(object s, System.Windows.Input.MouseEventArgs e) { da.To = 0.2f; sb.Children.Clear(); sb.Children.Add(da); sb.Begin(); cl = false; }; grr.MouseLeave += delegate(object s, System.Windows.Input.MouseEventArgs e) { da.To = 0; sb.Children.Clear(); sb.Children.Add(da); sb.Begin(); cl = false; }; }
private void Start_Animation() { double from = _isOpen ? this.ActualWidth / 3 : 0.0; double to = _isOpen ? 0 : this.ActualWidth / 3; Storyboard expandBoard = new Storyboard(); DoubleAnimation animation = new DoubleAnimation(); animation.From = from; animation.To = to; animation.Duration = new Duration(TimeSpan.FromMilliseconds(250)); Storyboard.SetTargetName(animation, "column2"); Storyboard.SetTargetProperty(animation, new PropertyPath("MaxWidth")); expandBoard.Children.Add(animation); DoubleAnimation animation2 = animation.Clone() as DoubleAnimation; Storyboard.SetTargetName(animation2, "column3"); expandBoard.Children.Add(animation2); this.BeginStoryboard(expandBoard); _isOpen = !_isOpen; }
private void Animate(UIElement element) { if (element.RenderTransform is ScaleTransform == false) { element.RenderTransform = new ScaleTransform(1.0, 1.0); element.RenderTransformOrigin = new Point(0.5, 0.5); } var xAnim = new DoubleAnimation() { From = 1.0, To = 1.05, Duration = new Duration(TimeSpan.FromSeconds(0.1)), AutoReverse = true, EasingFunction = new PowerEase(), }; var yAnim = xAnim.Clone(); var sb = new Storyboard(); sb.Children.Add(xAnim); sb.Children.Add(yAnim); Storyboard.SetTarget(xAnim, element); Storyboard.SetTargetProperty(xAnim, new PropertyPath("RenderTransform.(ScaleTransform.ScaleX)")); Storyboard.SetTarget(yAnim, element); Storyboard.SetTargetProperty(yAnim, new PropertyPath("RenderTransform.(ScaleTransform.ScaleY)")); sb.Begin(this); }
public void InAnimation(Action callback) { var expandAnimationA = _expandAnimation.Clone(); Storyboard.SetTarget(expandAnimationA, leftRec); Storyboard.SetTargetProperty(expandAnimationA, new PropertyPath(WidthProperty)); Storyboard.SetTarget(_expandAnimation, rightRec); Storyboard.SetTargetProperty(_expandAnimation, new PropertyPath(WidthProperty)); var brush = new SolidColorBrush(); leftRec.Fill = brush; rightRec.Fill = brush; RegisterName("brush", brush); Storyboard.SetTargetName(_colorAnimation, "brush"); Storyboard.SetTargetProperty(_colorAnimation, new PropertyPath(SolidColorBrush.ColorProperty)); var storyboard = new Storyboard(); storyboard.Children.Add(expandAnimationA); storyboard.Children.Add(_expandAnimation); storyboard.Children.Add(_colorAnimation); storyboard.Completed += (s, e) => { callback(); }; storyboard.Begin(this); }
public FrameworkElementStoryboardHandoffBehaviorExample() { WindowTitle = "Interactive Animation Example"; // Create a name scope for the page. NameScope.SetNameScope(this, new NameScope()); DockPanel myPanel = new DockPanel(); myPanel.Margin = new Thickness(20.0); containerBorder = new Border(); containerBorder.Background = Brushes.White; containerBorder.BorderBrush = Brushes.Black; containerBorder.BorderThickness = new Thickness(2.0); containerBorder.VerticalAlignment = VerticalAlignment.Stretch; interactiveEllipse = new Ellipse(); interactiveEllipse.Fill = Brushes.Lime; interactiveEllipse.Stroke = Brushes.Black; interactiveEllipse.StrokeThickness = 2.0; interactiveEllipse.Width = 25; interactiveEllipse.Height = 25; interactiveEllipse.HorizontalAlignment = HorizontalAlignment.Left; interactiveEllipse.VerticalAlignment = VerticalAlignment.Top; TranslateTransform interactiveTranslateTransform = new TranslateTransform(); this.RegisterName("InteractiveTranslateTransform", interactiveTranslateTransform); interactiveEllipse.RenderTransform = interactiveTranslateTransform; xAnimation = new DoubleAnimation(); xAnimation.Duration = TimeSpan.FromSeconds(4); yAnimation = xAnimation.Clone(); Storyboard.SetTargetName(xAnimation, "InteractiveTranslateTransform"); Storyboard.SetTargetProperty(xAnimation, new PropertyPath(TranslateTransform.XProperty)); Storyboard.SetTargetName(yAnimation, "InteractiveTranslateTransform"); Storyboard.SetTargetProperty(yAnimation, new PropertyPath(TranslateTransform.YProperty)); theStoryboard = new Storyboard(); theStoryboard.Children.Add(xAnimation); theStoryboard.Children.Add(yAnimation); containerBorder.MouseLeftButtonDown += new MouseButtonEventHandler(border_mouseLeftButtonDown); containerBorder.MouseRightButtonDown += new MouseButtonEventHandler(border_mouseRightButtonDown); containerBorder.Child = interactiveEllipse; myPanel.Children.Add(containerBorder); this.Content = myPanel; }
public AnimatedFrame() { Default = this; _fadeInStoryboard = new Storyboard { Name = "FadeInStoryboard" }; _opacityInAnimation = new DoubleAnimation { From = 0, To = 1, EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut }, BeginTime = TimeSpan.Zero, Duration = TimeSpan.FromMilliseconds(300) }; Storyboard.SetTargetProperty(_opacityInAnimation, new PropertyPath(OpacityProperty)); _scaleXInAnimation = new DoubleAnimation { From = 0.95, To = 1, EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut }, BeginTime = TimeSpan.Zero, Duration = TimeSpan.FromMilliseconds(300) }; _scaleYInAnimation = _scaleXInAnimation.Clone(); Storyboard.SetTargetProperty(_scaleXInAnimation, new PropertyPath("RenderTransform.ScaleX")); Storyboard.SetTargetProperty(_scaleYInAnimation, new PropertyPath("RenderTransform.ScaleY")); _fadeInStoryboard.Children.Add(_opacityInAnimation); _fadeInStoryboard.Children.Add(_scaleXInAnimation); _fadeInStoryboard.Children.Add(_scaleYInAnimation); _fadeOutStoryboard = new Storyboard { Name = "FadeOutStoryboard" }; _opacityOutAnimation = new DoubleAnimation { From = 1, To = 0, EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut }, BeginTime = TimeSpan.Zero, Duration = TimeSpan.FromMilliseconds(100) }; _fadeOutStoryboard.Children.Add(_opacityOutAnimation); Storyboard.SetTargetProperty(_opacityOutAnimation, new PropertyPath(OpacityProperty)); Navigated += AnimatedFrame_Navigated; }
private void SetUpAnimations() { animations = new DoubleAnimation[geoArray.Length]; handEnterStoryboards = new Storyboard[geoArray.Length]; handLeaveStoryboards = new Storyboard[geoArray.Length]; DoubleAnimation handEnterAnimation = new DoubleAnimation(); handEnterAnimation.From = 0.0; handEnterAnimation.To = 1.0; handEnterAnimation.Duration = TimeSpan.FromMilliseconds(50); if (!this.instrument.HoldNote) { handEnterAnimation.AutoReverse = true; } for (int i = 0; i < animations.Length; i++) { animations[i] = handEnterAnimation.Clone(); Storyboard.SetTargetName(animations[i], String.Format("brush{0}", i + 1)); Storyboard.SetTargetProperty(animations[i], new PropertyPath(SolidColorBrush.OpacityProperty)); handEnterStoryboards[i] = new Storyboard(); handEnterStoryboards[i].Children.Add(animations[i]); } // Hand leave animations enabled when the note is held by hand's user if (this.instrument.HoldNote) { DoubleAnimation handLeaveAnimation = new DoubleAnimation(); handLeaveAnimation.From = 1.0; handLeaveAnimation.To = 0.0; handLeaveAnimation.Duration = TimeSpan.FromMilliseconds(50); for (int i = 0; i < animations.Length; i++) { animations[i] = handLeaveAnimation.Clone(); Storyboard.SetTargetName(animations[i], String.Format("brush{0}", i + 1)); Storyboard.SetTargetProperty(animations[i], new PropertyPath(SolidColorBrush.OpacityProperty)); handLeaveStoryboards[i] = new Storyboard(); handLeaveStoryboards[i].Children.Add(animations[i]); } this.OnHandLeave += new NoteEventHandler(PlayLeaveAnimation); } this.OnHandEnter += new NoteEventHandler(PlayEnterAnimation); }
/// <summary> /// Fades out and collapses all the buttons on the start screen. /// </summary> private void FadeOutButtons(object sender, RoutedEventArgs e) { DoubleAnimation fadeAnimation = new DoubleAnimation { From = 1, To = 0, Duration = TimeSpan.FromSeconds(1) }; //I am doing this because using one animation for all buttons causes threading issues down the line. DoubleAnimation fadeAnimation1 = fadeAnimation.Clone(); DoubleAnimation fadeAnimation2 = fadeAnimation.Clone(); DoubleAnimation fadeAnimation3 = fadeAnimation.Clone(); fadeAnimation.Completed += CollapseStartPage; if ((System.Windows.Controls.Button)sender == cmdSettings) { fadeAnimation.Completed += ShowSettingsScreen; } if ((System.Windows.Controls.Button)sender == cmdStartGame) { fadeAnimation.Completed += ShowGameScreen; fadeAnimation.Completed += StartGame; } if ((System.Windows.Controls.Button)sender == cmdHistory) { fadeAnimation.Completed += ShowHistoryScreen; } cmdStartGame.BeginAnimation(System.Windows.Controls.Button.OpacityProperty, fadeAnimation); cmdSettings.BeginAnimation(System.Windows.Controls.Button.OpacityProperty, fadeAnimation1); cmdHistory.BeginAnimation(System.Windows.Controls.Button.OpacityProperty, fadeAnimation2); cmdAbout.BeginAnimation(System.Windows.Controls.Button.OpacityProperty, fadeAnimation3); }
public void SetUpAnimations() { // initialize animation & storyboard arrays animations = new DoubleAnimation[rectArray.Length]; startPlayingStoryboards = new Storyboard[rectArray.Length]; stopPlayingStoryboards = new Storyboard[rectArray.Length]; // create 0-1 opacity animation DoubleAnimation startPlayingAnimation = new DoubleAnimation(); startPlayingAnimation.From = 0.0; startPlayingAnimation.To = 1.0; startPlayingAnimation.Duration = TimeSpan.FromMilliseconds(100); // Set animation targets and add them to storyboards for (int i = 0; i < animations.Length; i++) { animations[i] = startPlayingAnimation.Clone(); Storyboard.SetTargetName(animations[i], String.Format("brush{0}", i)); Storyboard.SetTargetProperty(animations[i], new PropertyPath(SolidColorBrush.OpacityProperty)); startPlayingStoryboards[i] = new Storyboard(); startPlayingStoryboards[i].Children.Add(animations[i]); } // create 1-0 opacity animation DoubleAnimation stopPlayingAnimation = new DoubleAnimation(); stopPlayingAnimation.From = 1.0; stopPlayingAnimation.To = 0.0; stopPlayingAnimation.Duration = TimeSpan.FromMilliseconds(50); // set animation targets and add them to storyboards for (int i = 0; i < animations.Length; i++) { animations[i] = stopPlayingAnimation.Clone(); Storyboard.SetTargetName(animations[i], String.Format("brush{0}", i)); Storyboard.SetTargetProperty(animations[i], new PropertyPath(SolidColorBrush.OpacityProperty)); stopPlayingStoryboards[i] = new Storyboard(); stopPlayingStoryboards[i].Children.Add(animations[i]); } // Attach animations to events this.OnStartPlay += new NoteEventHandler(PlayStartAnimation); this.OnStopPlay += new NoteEventHandler(PlayStopAnimation); }
private void PutNumber(int n, int x, int y, bool delay = false, bool isReadOnly = false) { var text = this.texts[x, y]; text.Foreground = isReadOnly ? Brushes.Violet : Brushes.Thistle; text.Text = n > 0 ? $"{n}" : text.Text; var previewText = new FormattedText(text.Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(text.FontFamily, text.FontStyle, text.FontWeight, text.FontStretch), text.FontSize, text.Foreground); text.SetValue(Canvas.LeftProperty, OutlineThickness + x * this.CellSize + (this.CellSize - previewText.Width) / 2); text.SetValue(Canvas.TopProperty, OutlineThickness + y * this.CellSize + (this.CellSize - previewText.Height) / 2); var scaleTransform = text.RenderTransform as ScaleTransform ?? new ScaleTransform(1.0, 1.0, previewText.Width / 2, previewText.Height / 2); text.RenderTransform = scaleTransform; DoubleAnimation drop = new DoubleAnimation() { Duration = new Duration(PutDuration), BeginTime = delay ? TimeSpan.FromSeconds(this.r.NextDouble()) : TimeSpan.Zero, DecelerationRatio = 1.0, }; var show = drop.Clone(); if (n > 0) { drop.From = 10.0; drop.To = 1.0; show.From = 0.0; show.To = 1.0; } else { drop.From = 1.0; drop.To = 10.0; show.From = 1.0; show.To = 0.0; } scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, drop); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, drop); text.BeginAnimation(UIElement.OpacityProperty, show); }
void KeyGetRoundKeyGroupCompleted() { c_group++; if (c_group < 16) { KeyGetRoundKeyGroup(); } else { Color_RoundKeyCube(c_round, 0); Color_Ring(c_round, 3, 0); DoubleAnimation da = new DoubleAnimation(opacity_default, TimeSpan.FromSeconds(0.5)) { SpeedRatio = parent.sld_KS_Speed.Value }; DoubleAnimation db = da.Clone(); brush[0, 0].BeginAnimation(Brush.OpacityProperty, da); brush[1, 0].BeginAnimation(Brush.OpacityProperty, db); countdown(0.5, MethodBase.GetCurrentMethod().Name); } }
private void ChangeSceneLeft() { if (OpenWorldManager.GetScene(_sceneIndex - 1) == null || _isMapChanging) { int offset = _isMapChanging ? _mainCharacter.Sprites.SpriteWidth : 0; if (_mainCharacter.MoveTransform.X - 10 > 0 - offset) { _mainCharacter.MoveTransform.X -= 10; } else { _mainCharacter.MoveTransform.X = 0 - offset; } return; } _isMapChanging = true; Storyboard storyboard = new Storyboard(); DoubleAnimation opacityAnimation = new DoubleAnimation(); opacityAnimation.Duration = TimeSpan.FromMilliseconds(200); opacityAnimation.From = 0.0; opacityAnimation.To = 1.0; DoubleAnimation opacityAnimationCharacter = opacityAnimation.Clone(); opacityAnimationCharacter.From = 1.0; opacityAnimationCharacter.To = 0.0; storyboard.Children.Add(opacityAnimation); storyboard.Children.Add(opacityAnimationCharacter); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); Storyboard.SetTargetProperty(opacityAnimationCharacter, new PropertyPath(OpacityProperty)); Storyboard.SetTarget(opacityAnimation, bd_black_fade); Storyboard.SetTarget(opacityAnimationCharacter, _mainCharacter.CharacterPic); storyboard.Completed += (sender, e) => FadeOut(sender, e, true); storyboard.Begin(); }
public void OutAnimation() { var shrinkAnimationA = _shrinkAnimation.Clone(); Storyboard.SetTarget(shrinkAnimationA, leftRec); Storyboard.SetTargetProperty(shrinkAnimationA, new PropertyPath(WidthProperty)); var shrinkAnimationB = _shrinkAnimation; Storyboard.SetTarget(shrinkAnimationB, rightRec); Storyboard.SetTargetProperty(shrinkAnimationB, new PropertyPath(WidthProperty)); var storyboard = new Storyboard { Duration = new Duration(TimeSpan.FromSeconds(6)) }; storyboard.Children.Add(shrinkAnimationA); storyboard.Children.Add(shrinkAnimationB); storyboard.Completed += (s, e) => { Dispatcher.InvokeShutdown(); }; storyboard.Begin(); }
private void FadeOut(object sender, EventArgs e, bool left) { if (left) { _mainCharacter.MoveTransform.X = main_grid.ActualWidth - _mainCharacter.Sprites.SpriteWidth - 10; _mainCharacter.Direction = DirectionEnum.IDLELeft; _sceneIndex--; } else { _mainCharacter.MoveTransform.X = 10; _mainCharacter.Direction = DirectionEnum.IDLERight; _sceneIndex++; } LoadScene(); Storyboard storyboard = new Storyboard(); DoubleAnimation opacityAnimation = new DoubleAnimation(); opacityAnimation.Duration = TimeSpan.FromMilliseconds(200); opacityAnimation.From = 1.0; opacityAnimation.To = 0.0; DoubleAnimation opacityAnimationCharacter = opacityAnimation.Clone(); opacityAnimationCharacter.From = 0.0; opacityAnimationCharacter.To = 1.0; storyboard.Children.Add(opacityAnimation); storyboard.Children.Add(opacityAnimationCharacter); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); Storyboard.SetTargetProperty(opacityAnimationCharacter, new PropertyPath(OpacityProperty)); Storyboard.SetTarget(opacityAnimation, bd_black_fade); Storyboard.SetTarget(opacityAnimationCharacter, _mainCharacter.CharacterPic); storyboard.Completed += FadeIn; storyboard.Begin(); }
public void OutAnim(Action callback) { var anim = new DoubleAnimation { From = 1, To = 0, Duration = new Duration(TimeSpan.FromSeconds(3)), EasingFunction = new PowerEase { EasingMode = EasingMode.EaseInOut } }; DoubleAnimation animA = anim.Clone(); Storyboard.SetTarget(animA, leftRec); Storyboard.SetTargetProperty(animA, new PropertyPath(OpacityProperty)); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(animA); storyboard.Completed += (s, e) => { callback(); }; storyboard.Begin(this); }
/// <summary> /// On apply template event handler. /// </summary> public override void OnApplyTemplate() { const string Ellipse = "ellipse"; const int Duration = 50; const int NumberOfElements = 8; const double Speed = 0.15; base.OnApplyTemplate(); var listBox = GetTemplateChild("listBox") as ListBox; var storyboard = GetTemplateChild("storyboard") as Storyboard; if (listBox == null) { // ReSharper disable once NotResolvedInText throw new ArgumentNullException("ListBox is null."); } if (storyboard == null) { // ReSharper disable once NotResolvedInText throw new ArgumentNullException("Storyboard is null."); } // Get all animated elements. var ellipses = new List <Ellipse>(); for (var i = 1; i <= NumberOfElements; i++) { var ellipse = GetTemplateChild(Ellipse + i) as Ellipse; if (ellipse == null) { // ReSharper disable once NotResolvedInText throw new ArgumentNullException("Ellipse is null."); } ellipse.Fill = new SolidColorBrush(Colors.Gray); ellipses.Add(ellipse); } // Create a name scope. NameScope.SetNameScope(this, new NameScope()); double time = 0; for (var i = 0; i < 8; i++) { time += Speed; var previous = i == 0 ? NumberOfElements - 1 : i - 1; var previous2 = (previous - 1) == -1 ? NumberOfElements - 1 : previous - 1; var next = i + 1 == NumberOfElements ? 0 : i + 1; var next2 = (next + 1) == NumberOfElements ? 0 : (next + 1); var animation1 = new DoubleAnimation { To = 3, Duration = new Duration(TimeSpan.FromMilliseconds(Duration)), BeginTime = TimeSpan.FromSeconds(time) }; var animation2 = animation1.Clone(); Storyboard.SetTargetName(animation2, ellipses[previous2].Name); Storyboard.SetTargetProperty(animation2, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetName(animation1, ellipses[previous2].Name); Storyboard.SetTargetProperty(animation1, new PropertyPath(FrameworkElement.HeightProperty)); var animation3 = new DoubleAnimation { To = 4, Duration = new Duration(TimeSpan.FromMilliseconds(Duration)), BeginTime = TimeSpan.FromSeconds(time) }; var animation4 = animation3.Clone(); Storyboard.SetTargetName(animation3, ellipses[previous].Name); Storyboard.SetTargetProperty(animation3, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetName(animation4, ellipses[previous].Name); Storyboard.SetTargetProperty(animation4, new PropertyPath(FrameworkElement.HeightProperty)); var animation5 = new DoubleAnimation { To = 5, Duration = new Duration(TimeSpan.FromMilliseconds(Duration)), BeginTime = TimeSpan.FromSeconds(time) }; var animation6 = animation5.Clone(); Storyboard.SetTargetName(animation5, ellipses[i].Name); Storyboard.SetTargetProperty(animation5, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetName(animation6, ellipses[i].Name); Storyboard.SetTargetProperty(animation6, new PropertyPath(FrameworkElement.HeightProperty)); var animation7 = new DoubleAnimation { To = 1, Duration = new Duration(TimeSpan.FromMilliseconds(Duration)), BeginTime = TimeSpan.FromSeconds(time) }; var animation8 = animation7.Clone(); Storyboard.SetTargetName(animation7, ellipses[next].Name); Storyboard.SetTargetProperty(animation7, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetName(animation8, ellipses[next].Name); Storyboard.SetTargetProperty(animation8, new PropertyPath(FrameworkElement.HeightProperty)); var animation9 = new DoubleAnimation { To = 2, Duration = new Duration(TimeSpan.FromMilliseconds(Duration)), BeginTime = TimeSpan.FromSeconds(time) }; var animation10 = animation9.Clone(); Storyboard.SetTargetName(animation9, ellipses[next2].Name); Storyboard.SetTargetProperty(animation9, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetName(animation10, ellipses[next2].Name); Storyboard.SetTargetProperty(animation10, new PropertyPath(FrameworkElement.HeightProperty)); storyboard.Children.Add(animation1); storyboard.Children.Add(animation2); storyboard.Children.Add(animation3); storyboard.Children.Add(animation4); storyboard.Children.Add(animation5); storyboard.Children.Add(animation6); storyboard.Children.Add(animation7); storyboard.Children.Add(animation8); storyboard.Children.Add(animation9); storyboard.Children.Add(animation10); } storyboard.Begin(listBox); }
/// <summary> /// The TossBall method is called to toss the ball. /// </summary> public void TossBall() { try { if (_ballStoryBoard == null) { // Initialize the story board. _ballStoryBoard = new Storyboard(); _ballStoryBoard.Completed += new EventHandler(BallStopped); } else if (_ballStoryBoard.GetCurrentState(_ballControl) == ClockState.Stopped || _ballStoryBoard.GetIsPaused(_ballControl)) { return; // Ball is already moving or is paused - do not spin. } // Ball spinning animation 1. if (_ballSpinningAnimation1 == null) { // Initialize the ball spinning animation. _ballSpinningAnimation1 = new DoubleAnimation(); _ballSpinningAnimation1.SpeedRatio = Constants.BallSpeedRatio; Storyboard.SetTargetName(_ballSpinningAnimation1, Constants.BallRotateTransformName); Storyboard.SetTargetProperty(_ballSpinningAnimation1, new PropertyPath(RotateTransform.AngleProperty)); _ballStoryBoard.Children.Add(_ballSpinningAnimation1); // Add the animation to the story board. } // Number of rotations in total degrees - multiply by ball speed ratio (positive degrees for clockwise). _ballSpinningAnimation1.From = 0; _ballSpinningAnimation1.To = _winningNumberEndAngleDegrees + (Constants.FullCircleDegrees * Constants.BallSpeedRatio); // Duration of spin seconds - multiply by ball speed ratio. TimeSpan ballSpinningDuration = _wheelSpinningAnimation1EndTime.Subtract(DateTime.Now); _ballSpinningAnimation1.Duration = TimeSpan.FromSeconds(ballSpinningDuration.TotalSeconds * Constants.BallSpeedRatio); // Ball falling animation. if (_ballFallingAnimation == null) { // Initialize the ball falling animation. _ballFallingAnimation = new DoubleAnimation(); _ballFallingAnimation.SpeedRatio = Constants.BallSpeedRatio; Storyboard.SetTargetName(_ballFallingAnimation, Constants.BallTranslateTransformName); Storyboard.SetTargetProperty(_ballFallingAnimation, new PropertyPath(TranslateTransform.YProperty)); _ballStoryBoard.Children.Add(_ballFallingAnimation); // Add the animation to the story board. } // Distance for the ball to fall in pixels. _ballFallingAnimation.From = _ballCenterPositionYPixels - _ballYOffsetPixels; // Start at the top-edge of the wheel. _ballFallingAnimation.To = _ballCenterPositionYPixels - (_ballYOffsetPixels * Constants.BallFallPercent); // Duration of fall in seconds - same as rotation duration. _ballFallingAnimation.Duration = _ballSpinningAnimation1.Duration; // Ball spinning animation 2. if (_ballSpinningAnimation2 == null) { // Initialize the ball spinning animation - it is a clone of the second wheel spinning animation. _ballSpinningAnimation2 = _wheelSpinningAnimation2.Clone(); Storyboard.SetTargetName(_ballSpinningAnimation2, Constants.BallRotateTransformName); Storyboard.SetTargetProperty(_ballSpinningAnimation2, new PropertyPath(RotateTransform.AngleProperty)); _ballStoryBoard.Children.Add(_ballSpinningAnimation2); // Add the animation to the story board. } // Begin time - begins after the first ball spinning animation. _ballSpinningAnimation2.BeginTime = TimeSpan.FromSeconds(ballSpinningDuration.TotalSeconds); // Ball sound. if (_ballMediaTimeLine == null) { _ballMediaTimeLine = new MediaTimeline(); //_ballMediaTimeLine.SpeedRatio = Constants.BallSpeedRatio; _ballMediaTimeLine.FillBehavior = FillBehavior.Stop; _ballMediaTimeLine.Source = new Uri(Directory.GetCurrentDirectory() + Constants.BallAudioFile, UriKind.Relative); Storyboard.SetTarget(_ballMediaTimeLine, _ballMediaElement); _ballStoryBoard.Children.Add(_ballMediaTimeLine); } //_ballMediaTimeLine.Duration = TimeSpan.FromSeconds(ballSpinningDuration.TotalSeconds * Constants.BallSpeedRatio); _ballMediaTimeLine.Duration = TimeSpan.FromSeconds(ballSpinningDuration.TotalSeconds); _ballControl.Visibility = Visibility.Visible; _ballStoryBoard.Begin(_ballControl, true); // Start the story board. OnBallTossed?.Invoke(true); // Publish the status of the ball. } catch (Exception ex) { throw new Exception("RouletteBall.TossBall(): " + ex.ToString()); } }
private void AnimationText() { Canvas mainPanel = canvas1; mainPanel.Background = Brushes.Black; m_txb = new TextBlock(); m_txb.Text = "Boas Festas!!! - Verax---"; m_txb.FontSize = 80; m_txb.Foreground = Brushes.Lime; DropShadowEffect eff = new DropShadowEffect(); eff.BlurRadius = 25; // Color="LightGreen" ShadowDepth="0" Direction="0" BlurRadius="25" eff.Color = Colors.Yellow; eff.ShadowDepth = 0; eff.Direction = 0; m_txb.Effect = eff; m_txb.SetValue(Canvas.LeftProperty, 10.0); m_txb.SetValue(Canvas.TopProperty, 10.0); mainPanel.Children.Add(m_txb); // m_txb.SetValue(Canvas.LeftProperty, 180.0); // m_txb.SetValue(Canvas.TopProperty, 1800.0); //create an animation DoubleAnimation db = new DoubleAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; ElasticEase elastic = new ElasticEase(); elastic.Oscillations = 2; elastic.Springiness = 2; CircleEase circle = new CircleEase(); circle.Ease(3); //db.EasingFunction = circle; //elastic; // BounceOrientation; //set from animation to start position //dont forget set canvas.left for grid if u dont u will get error db.From = 400; //set second position of grid db.To = 00; //set duration db.Duration = new Duration(TimeSpan.FromSeconds(3)); db.AutoReverse = true; db.EasingFunction = BounceOrientation; DoubleAnimation dc = db.Clone(); dc.EasingFunction = elastic; Storyboard sb = new Storyboard(); sb.Children.Add(db); sb.Children.Add(dc); Storyboard.SetTarget(db, m_txb); Storyboard.SetTarget(dc, m_txb); Storyboard.SetTargetProperty(db, new PropertyPath(Canvas.TopProperty)); Storyboard.SetTargetProperty(dc, new PropertyPath(Canvas.LeftProperty)); //Storyboard.SetTargetProperty(db, Canvas.LeftProperty); GradientStopCollection gcolFrom = new GradientStopCollection(); gcolFrom.Add(new GradientStop(Colors.Black, 10)); GradientStopCollection gcolTo = new GradientStopCollection(); gcolFrom.Add(new GradientStop(Colors.Red, 10)); LinearGradientBrushAnimation linan = new LinearGradientBrushAnimation(); linan.From = new LinearGradientBrush(gcolFrom, 90); linan.To = new LinearGradientBrush(gcolTo, 90); this.RegisterName("linan", linan); sb.Children.Add(linan); Storyboard.SetTargetName(linan, "linan"); Storyboard.SetTargetProperty(linan, new PropertyPath(TextBlock.ForegroundProperty)); System.Diagnostics.Debug.WriteLine("m_veraxTxb.BeginAnimation(Canvas.LeftProperty, db..."); //m_txb.BeginAnimation(Canvas.LeftProperty, db); canvas1.Resources.Add("unique_id", sb); sb.Begin(); }
protected override Freezable CreateInstanceCore() { return(internalAnimation.Clone());; }