我想制作一个小型命运之轮游戏,但在制作旋转图像的事件时遇到问题
这是我现在拥有的代码,但它似乎只运行 _thread 一次
private readonly Timer _timer;
private Thread _thread;
private int _angle;
public MainWindow()
{
InitializeComponent();
_timer = new Timer(500);
_timer.Elapsed += RotateWheelEvent;
_timer.Start();
_angle = 0;
SetupRotationThread();
_thread.Start();
}
public void RotateWheelEvent(object sender, EventArgs args)
{
_thread.Abort();
_angle = _angle + 15;
_thread.Start();
}
public void SetupRotationThread()
{
var rotatetransform = new RotateTransform(_angle);
_thread = new Thread(
delegate()
{
ImageWheel.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.SystemIdle,
TimeSpan.FromSeconds(1),
new Action(
delegate()
{
ImageWheel.RenderTransformOrigin = new Point(0.5, 0.5);
ImageWheel.RenderTransform = rotatetransform;
}
));
});
}