I'm making simple game where I need to remove pictures after certain time without freezing everything else. I'm making explode event:
private void Explode(int x, int y)
{
PictureBox explosion = new PictureBox();
explosion.Image = Properties.Resources.explosion;
explosion.SizeMode = PictureBoxSizeMode.StretchImage;
explosion.Size = new Size(50, 50);
explosion.Tag = "explosion";
explosion.Left = x;
explosion.Top = y;
this.Controls.Add(explosion);
explosion.BringToFront();
}
I have already one timer for running the game, and i want to use if statement to remove picture when it lasts for 3 sec.
private void timer1_Tick(object sender, EventArgs e)
{
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "explosion")
{
if (EXPLOSION LASTS MORE THEN 3sec)
{
this.Controls.Remove(x);
}
}
}
}
How can I do this?