90도 회전하고, 길이가 늘어나는 애니메이션을 구현중인데 질문사항이 있어 글올립니다.
<Canvas x:Name="CvRobot"
Width="200" Height="50" Canvas.Left="245" Canvas.Top="204" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="295,244,0,0">
<Rectangle Width="120" Height="50"
Stroke="Black"
StrokeThickness="0.5"
Fill="Gray"
RadiusX="25" RadiusY="25"/>
<Rectangle Width="100" Height="40" Canvas.Left="80" Canvas.Top="5"
Stroke="Black"
StrokeThickness="0.5"
Fill="Gray"
RadiusX="25" RadiusY="25"/>
<Ellipse Width="50" Height="40" Fill="GreenYellow" Canvas.Left="155" Canvas.Top="5"/>
<Rectangle Width="40" Height="30" Fill="White" Canvas.Left="180" Canvas.Top="10"/>
</Canvas>
c# 코드
private void Button_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation rotateAnimation = new DoubleAnimation
{
To = 90,
Duration = TimeSpan.FromSeconds(3)
};
DoubleAnimation scaleAnimation = new DoubleAnimation
{
To = 2.0,
Duration = TimeSpan.FromSeconds(1),
// BeginTime = TimeSpan.FromSeconds(3)
};
RotateTransform rotateTransform = new RotateTransform(0, 0, 40);
ScaleTransform scaleTransform = new ScaleTransform()
{
CenterX = 0,
CenterY = 40
};
TransformGroup transformGroup = new TransformGroup();
transformGroup.Children.Add(rotateTransform);
transformGroup.Children.Add(scaleTransform);
.
CvRobot.RenderTransform = transformGroup;
rotateTransform.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
}
코드는 이렇습니다. 제가 구현하고 싶은거는 90 도 회전하고, 한쪽 방향으로만 길이가 늘어나는 것을 원하는데, 이렇게 구현하면 회전 및 길이연장은 제대로 되는데 문제가 중심이 바뀌어 위치가 이동됩니다.
중심점이 문제인거 같은데 아무리 바꿔바도 잘 안되네요…
도움 좀 부탁드립니다. 아니면 더 좋은 방법 있으시면 알려주시고요.
로봇 팔 같은건데, 중심을 기준으로 회전하고, 길이가 늘어는것을 구현하고 싶습니다. 개별 애니메이션은 따로 따로, 예를 들어 45도 회전 그후 길이연장, 길이 축소 또 45도 회전 이런식으로요.
감사합니다.