UWP app矩形旋转

时间:2016-06-23 18:37:23

标签: c# uwp rotatetransform

我创建了一个Rectangle(敌人)。这个矩形射了一颗子弹。当子弹达到窗口边缘时,设置子弹可见性折叠。矩形旋转90度后,但我得到一个错误。为什么不旋转?

我从这个错误中截取了一个屏幕截图: Picture

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();
}

0 个答案:

没有答案