Dim
Dim

Reputation: 4807

Moving object animation in X and Y

I have created animation for moving object in X, but how do I add also Y?

TranslateTransform trans = new TranslateTransform();
Pointer.RenderTransform = trans;
DoubleAnimation anim2 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim2.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim2.Completed += new EventHandler(myanim_Completed);
trans.BeginAnimation(TranslateTransform.XProperty, anim2);

Upvotes: 2

Views: 888

Answers (2)

Rohit Vats
Rohit Vats

Reputation: 81243

Use StoryBoard and add both animations as child:

Storyboard storyBoard = new Storyboard
                    { Duration = new Duration(TimeSpan.FromMilliseconds(325)) };

DoubleAnimation anim2 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim2.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim2.Completed += new EventHandler(myanim_Completed);
Storyboard.SetTarget(anim2, trans);
Storyboard.SetTargetProperty(anim2, new PropertyPath(TranslateTransform.XProperty));

DoubleAnimation anim1 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim1.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim1.Completed += new EventHandler(myanim_Completed);
Storyboard.SetTarget(anim1, trans);
Storyboard.SetTargetProperty(anim1, new PropertyPath(TranslateTransform.YProperty));

storyBoard.Children.Add(anim2);
storyBoard.Children.Add(anim1);

storyBoard.Begin();

Upvotes: 2

Dim
Dim

Reputation: 4807

Figured out an answer:

        TranslateTransform trans = new TranslateTransform();
        Pointer.RenderTransform = trans;
        DoubleAnimation animX = new DoubleAnimation(0, 750, TimeSpan.FromMilliseconds(325));
        DoubleAnimation animY = new DoubleAnimation(0, 100, TimeSpan.FromMilliseconds(325));

        animX.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
        animY.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };

        animX.Completed += new EventHandler(myanim_Completed);
        trans.BeginAnimation(TranslateTransform.XProperty, animX);
        trans.BeginAnimation(TranslateTransform.YProperty, animY);

Upvotes: 0

Related Questions