Jermain Defo
Jermain Defo

Reputation: 189

Foreach loop with images

I have an 80 PNG image sequence in which I am trying to create an animation for my windows app. The file path is Assets/Star/ and I am trying to figure out how I would make a foreach loop for each image in the folder, so it would set the image object as Image1 then after a certain amount of ticks with the timer it would change it to Image2 and so on, here is what I have so far:

private void SubmitButton_Click(object sender, RoutedEventArgs e)
   {
      if(LevelUp == true)
        {
            string ImagePath = "Assets/Star/";
            foreach (Image item in ImagePath)
            {

            }
        }
   }

However I dont think im approaching it correctly, does anyone know how i should approach this?

Upvotes: 1

Views: 1562

Answers (1)

Servy
Servy

Reputation: 203802

Just await Task.Delay to asynchronously wait for a set span of time:

private async void SubmitButton_Click(object sender, RoutedEventArgs e)
{
    if (LevelUp)
    {
        string imagePath = "Assets/Star/";
        foreach (Image image in GetImages(imagePath))
        {
            ShowImage(image);
            await Task.Delay(timeToWait);
        }
    }
}

Upvotes: 2

Related Questions