I currently using the TranslateTransform on an image by code in my App and it's working correctly.
But I would like the image to move by step, let's say jump 10 or 20 pixel on each movement. Is there a way to do this. This to give a retro flavor to the movement.
I was thinking something like TranslateTransform.Step = 10;
Duration durationX = new TimeSpan(0, 0, 0, 0, 600);
Duration durationY = new TimeSpan(0, 0, 0, 0, 400);
DoubleAnimation moveX = new DoubleAnimation();
moveX.Duration = durationX;
moveX.To = ((ImgCanvasCoordinates[cardSource][0] - ImgCanvasCoordinates[cardTarget][0]) * -1);
DoubleAnimation moveY = new DoubleAnimation();
moveY.Duration = durationY;
moveY.To = ((ImgCanvasCoordinates[cardSource][1] - ImgCanvasCoordinates[cardTarget][1]) * -1);
Storyboard story1 = new Storyboard();
story1.Children.Add(moveX);
story1.Children.Add(moveY);
Storyboard.SetTarget(moveX, imgGhost);
Storyboard.SetTarget(moveY, imgGhost);
Storyboard.SetTargetProperty(moveX, "(Image.RenderTransform).(TranslateTransform.X)");
Storyboard.SetTargetProperty(moveY, "(Image.RenderTransform).(TranslateTransform.Y)");
story1.Begin();
You can use a custom
EasingFunctionto achieve this.By writing an
EasingFunctionyou can fully control the movement of animation. I've written aStepEasingFunctionas shown below:Then, just add an EasingFunction assigning to the animations:
Then, how to calculate the value of the
NormalizedStepproperty?You said that you want a 10-pixel movement for each step, so calculate the step total count and use
1 / stepTotalCountto calculate the finalNormalizedStepproperty.