Xamarin.Android 2D frame by frame animations

I'm currently trying to make a game project containing custome made frame by frame animations, my problem is that I can't make 2 animations accure at the same time, I know how to make one animation after another but can't figure out how to make multiple animations simultaneously.

AnimationDrawable animation;
ivPlayer1.SetImageResource(ShootAnimation);
animation = (AnimationDrawable)ivPlayer1.Drawable;
animation.Start();
I've been also trying to delay animations using handlers but I don't know what they do:

Handler h = new Handler();
Action changeAnimations = () =>
{
animatiosn and stuff...
}
h.PostDelayed(changeAnimations, animation.NumberOfFrames * 50);

Answers

  • AmmarMheirAmmarMheir USMember, Forum Administrator, Xamarin Team Xamurai

    In order to play more than one animation at the same time, you can use AnimationSet to set a group of animations to be played together.

    Looking through the Android documentation, it seems that AnimationDrawable is mainly used for animating simple logos / UI elements, this is likely why you are seeing this behavior so that the Main UI thread wont get blocked when attempting to start multiple animations, potentially freezing up the UI.

    If you like, you may find it easier to work with the opened sourced MonoGame framework that allows you to create cross platform 2D / 3D games. It's based off of Microsoft's XNA game framework:
    https://docs.microsoft.com/en-us/xamarin/graphics-games/monogame/

    It's a fully fledged game engine which might give you a lot more flexibility when creating a game project.

Sign In or Register to comment.