我正在用c#创建《Flappy Bird》游戏。到目前为止,代码工作完美,但我添加了一个GIF说游戏结束,这张图片只显示一旦timer1
停止。
我怎么才能做到呢?
下面是GIF图像的代码片段(我尝试了这两个代码片段,虽然没有错误,但它们都不起作用):
private void pictureBox5_Click(object sender, EventArgs e)
{
if (timer2.Enabled)
{
pictureBox5.Show();
}
else
{
pictureBox5.Hide();
}
}
下面是timer2
的代码片段private void timer2_Tick(object sender, EventArgs e)
{
if (!timer1.Enabled)
{
timer2.Enabled = true;
timer2.Start();
}
}
要禁用Timer1
,必须先禁用Timer2
,再禁用Timer1
。
private void Timer1_Tick(object sender, EventArgs e)
{
//For example, the gamer has 20 seconds
//So, we set the value of Label1.text to 20
if (int.Parse(Label1.Text) > 0)
{
int Counter = int.Parse(Label1.Text);
Counter--;
Label1.Text = Counter.ToString();
}
else
{
Timer2.Enabled = true;
Timer1.Enabled = false;
}
}
private void pictureBox4_Click(object sender, EventArgs e)
{
if (Timer2.Enabled == true)
{
pictureBox5.Show();
}
else
{
pictureBox5.Hide();
}
}
测试:
Visual Studio 2017
.NET Framework 4.5.2
Windows Forms