I made Animation into a class, how do I use it to draw the animation onto an area in my program?

I put Animation as a class in my game, but can’t figure out how to pass it the variables (a list of Sprites, Sprite is also a class) and my college’s wiki doesn’t help as they have animated by using Sprite as a class and letting the list be handled in the run time by varying the frame they are on. How do I get my way and my Animation class to work?

Classes for Sprite and Animation below

internal class Sprite //The sprite. multiple of these for each animation
    {
        private string SpriteName;
        private Texture2D SpriteTexture;
        private Image SpriteImg;
        public Vector2 Position;
        public Sprite(Texture2D sp)
        {
            SpriteTexture = sp;
        }
       
    }

    internal class Animation //Animations. A list of sprites.
    {
        private List<Sprite> Sprites;
        public Animation(List<Sprite> sprites)
        {
            Sprites = sprites;
        }
    }

How I tried to draw the animation down below

PlayerAnimation = Animation(List <Sprite> < "AnimTest1", "AnimTest2", "AnimTest3", "AnimTest4", "AnimTest5" >> );

PlayerAnimation is already defined, and System.Collections.Generic is used for List. AnimTest 1-5 are the Sprites I am attempting to pass it.
Any help appreciated. Thanks in advance.

This thread should be of some use

https://community.monogame.net/t/youtube-video-feedback-video-tutorials-for-monogame/17168/57

EDIT

Before I forget:

Hi @Ultima_DoombotMK1, Welcome to the Community!

Happy Coding!

1 Like

The easiest way would be to first instantiate the list of animations into a new System.Collections.Generic.List. In c# you need to do this using the new keyword:

var sprites = new List<Sprite>
{
AnimTest1, AnimTest2, AnimTest3, AnimTest4, AnimTest5
}

Then instantiate your new Animation object, passing the list instance to the constructor:

PlayerAnimation = new Animation(sprites);

Hope this helps. Cheers!

I don’t think that one will work, since Animation isn’t a method, function, etc. It already threw that error at me when I tried doing it that way before. Thanks for the tip about putting the sprites into a list, though, that might do something.