我创建了一个Rectangle(敌人)。这个矩形射了一颗子弹。当子弹达到窗口边缘时,设置子弹可见性折叠。矩形旋转90度后,但我得到一个错误。为什么不旋转?
Enemy.cs
public void rotateEnemy(Rectangle enemy)
{
RotateTransform transform = new RotateTransform()
{
CenterX = 0.5,
CenterY = 0.5,
Angle = 90,
};
enemy.RenderTransformOrigin = new Point(0.5, 0.5);
enemy.RenderTransform = transform;
Storyboard storyboard = new Storyboard();
DoubleAnimation rotate = new DoubleAnimation();
rotate.From = 0;
rotate.To = 90;
rotate.Duration = new Duration(TimeSpan.FromSeconds(2));
rotate.AutoReverse = false;
rotate.SetValue(Storyboard.TargetNameProperty, bullet.Name);
Storyboard.SetTarget(rotate, bullet);
Storyboard.SetTargetProperty(rotate, "(UIElement.RenderTransform).(RotateTransform.Angle)"));
storyboard.Children.Add(rotate);
storyboard.Begin();
}