I am creating a 2D platform game in a wpf application... and I tried to make my character walk with a gif animation.
Here's my C# code:
private void imgMega_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Right)
{
if (Grid.GetColumn(imgMega) <= Grid.ColumnDefinitions.Count - 1)
Grid.SetColumn(imgMega, Grid.GetColumn(imgMega) + 1);
BitmapImage bmi = new BitmapImage(new Uri("megaman.gif", UriKind.Relative));
imgMega.Source = bmi;
}
} /*---- When my character walk ----*/
private void imgMega_OnKeyUp(object sender, KeyEventArgs e)
{
BitmapImage bmi = new BitmapImage(new Uri("Megaman8bit.jpg", UriKind.Relative));
imgMega.Source = bmi;
} /*---- When my character stop walking ----*/
And my XAML code:
<Image Name="imgMega" Width="60" Grid.ColumnSpan="4" FocusVisualStyle="{x:Null}" Source="Megaman8bit.jpg" Focusable="True" KeyDown="imgMega_OnKeyDown" KeyUp="imgMega_OnKeyUp"/>
* My "megaman.gif" image is my walking character and my "Megaman8bit.jpg" image is my immobile character. *
With this code, the character changes his position but the gif animation doesn't work... Somebody can help me to find what's wrong ?