예제 #1
0
        private static SplineDoubleKeyFrame CreateDoubleAnimation(ref Storyboard sb,
                                                                  TranslateTransform translation, PropertyPath property)
        {
            DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();

            da.SetValue(NameProperty, string.Concat("da_", property));

            SplineDoubleKeyFrame sdkf = new SplineDoubleKeyFrame();

            sdkf.SetValue(NameProperty, string.Concat("sdkf_", property));

            sdkf.Value   = 0;
            sdkf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.25));

            //define the KeySpline
            KeySpline ksX = new KeySpline();

            ksX.ControlPoint1 = new Point(1.0, 0.25);
            ksX.ControlPoint2 = new Point(0.75, 1.0);
            sdkf.KeySpline    = ksX;

            //add the SplineDoubleKeyFrame to the DoubleAnimationUsingKeyFrames
            da.KeyFrames.Add(sdkf);

            //define which TranslateTransform property will be targeted by the DoubleAnimation
            Storyboard.SetTarget(da, translation);
            Storyboard.SetTargetProperty(da, property);
            sb.Children.Add(da);
            return(sdkf);
        }
예제 #2
0
        /**
         * Animation nach einer entfernten Zeile
         *
         * Fast wie die animateRemovedLinesHard, nur nicht explosiv.
         */
        private void animateRemovedLinesSoft(List <int> removedLines)
        {
            Storyboard sb = new Storyboard();

            List <Rectangle> animatedRectangled = new List <Rectangle>();

            foreach (int y in removedLines)
            {
                for (int i = 0; i < boardModel.getColumns(); i++)
                {
                    Rectangle rectOnBoard = getRectangleAt(i, y);
                    Rectangle rect        = new Rectangle();
                    rect.Height = rectOnBoard.ActualHeight;
                    rect.Width  = rectOnBoard.ActualWidth;
                    rect.Fill   = rectOnBoard.Fill;

                    System.Windows.Point p = rectOnBoard.TransformToVisual(this.LayoutRoot).Transform(new System.Windows.Point(0, 0));

                    canvas.Children.Add(rect);
                    Canvas.SetLeft(rect, p.X + Canvas.GetLeft(LayoutRoot));
                    Canvas.SetTop(rect, p.Y + Canvas.GetTop(LayoutRoot));


                    CompositeTransform ct = new CompositeTransform();
                    ct.CenterX           = rect.ActualWidth / 2;
                    ct.CenterY           = rect.ActualHeight / 2;
                    rect.RenderTransform = ct;


                    //Bewegung
                    DoubleAnimationUsingKeyFrames dauk = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTargetProperty(dauk, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)"));
                    Storyboard.SetTarget(dauk, rect);


                    SplineDoubleKeyFrame sdk = new SplineDoubleKeyFrame();
                    sdk.SetValue(SplineDoubleKeyFrame.ValueProperty, (double)(-1 * rnd.Next(10)));
                    sdk.KeyTime = TimeSpan.FromMilliseconds(rnd.Next(400));
                    KeySpline ks = new KeySpline();
                    ks.ControlPoint1 = new System.Windows.Point(0, 1);
                    ks.ControlPoint2 = new System.Windows.Point(1, 1);
                    sdk.KeySpline    = ks;
                    dauk.KeyFrames.Add(sdk);

                    SplineDoubleKeyFrame sdk0 = new SplineDoubleKeyFrame();
                    sdk0.SetValue(SplineDoubleKeyFrame.ValueProperty, (double)rnd.Next(474));
                    sdk0.KeyTime = TimeSpan.FromMilliseconds(1000);
                    KeySpline ks0 = new KeySpline();
                    ks0.ControlPoint1 = new System.Windows.Point(1, 0);
                    ks0.ControlPoint2 = new System.Windows.Point(1, 1);
                    sdk0.KeySpline    = ks0;
                    dauk.KeyFrames.Add(sdk0);
                    //Drehung
                    //-------------------------------
                    DoubleAnimation da = new DoubleAnimation();
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.Rotation)"));
                    Storyboard.SetTarget(da, rect);
                    da.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
                    int fac = rnd.Next(2) == 0 ? -1 : 1;

                    da.To             = fac * 360.0;
                    da.RepeatBehavior = RepeatBehavior.Forever;


                    //--Opacity
                    DoubleAnimationUsingKeyFrames dauk2 = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(dauk2, rect);
                    Storyboard.SetTargetProperty(dauk2, new PropertyPath("Opacity"));

                    SplineDoubleKeyFrame sdk3 = new SplineDoubleKeyFrame();
                    sdk3.SetValue(SplineDoubleKeyFrame.ValueProperty, 0.0);
                    KeySpline ks3 = new KeySpline();
                    ks3.ControlPoint1 = new System.Windows.Point(0, 0.5);
                    ks3.ControlPoint2 = new System.Windows.Point(1, 0.5);
                    sdk3.KeySpline    = ks3;
                    sdk3.KeyTime      = TimeSpan.FromMilliseconds(1000);
                    dauk2.KeyFrames.Add(sdk3);



                    sb.Children.Add(dauk);
                    sb.Children.Add(da);
                    sb.Children.Add(dauk2);
                    animatedRectangled.Add(rect);
                }
            }
            if (!LayoutRoot.Resources.Contains("unique_id"))
            {
                LayoutRoot.Resources.Add("unique_id", sb);
            }
            sb.Duration   = TimeSpan.FromMilliseconds(1000);
            sb.Completed += new EventHandler((a, b) =>
            {
                foreach (var rect in animatedRectangled)
                {
                    canvas.Children.Remove(rect);
                }
            });
            sb.Begin();
        }