Animation

Hello,

Firstly, I would like to say thank you for visiting this thread. I would like to discuss how I would be able to achieve movement for my ‘collectible’ assets within levels in my game; I know this is not extremely specific, but I would at least like to know how to implement animation + create a collision effect (ONLY FOR MY GAME CHARACTER)

Please leave a message below if you’d like me to elaborate on some things.

Do you want help on how to move your collectables around or are you just asking about the animation? Do you want sprite sheet animation? Or skinned animation (based on bones)? For collision is an axis-aligned bounding box sufficient? Or maybe you want the collision to be more precise, or dependent on the frame in the animation?

I would absolutely love some assistance on moving my collectables around, but I’d also like a sprite sheet animation created as I am quite stuck. I believe an axis-aligned bounding box would be sufficient for the collision; it does not matter too much on the frame.

Would it be okay if we privately spoke about this via e-mail, or any other platforms?

You can send a private message using this forum if you want, but you’ll probably get better help if you just post your questions here. MonoGame has none of that stuff for animation or collision built in, but there are a bunch of people on the forums that built their own classes on top of MG. Some might be able to help you out. E.g. MonoGame.Extended probably has spritesheet support. Cc @LithiumToast and @craftworkgames
If you have some questions that you would rather not post publicly, feel free to send a private message though.

Thank you for the references, definitely helps a lot! I was just wondering if you knew how I could draw two collectible sprites in my game at the same time?

If you have the texture loaded, you can just make two SpriteBatch.Draw calls to render it twice. If the collectibles are animated you could have multiple instances of a Collectible class, each with their own counter for the frame of the animation they’re in and a position and both with a reference to the spritesheet texture. How you do that exactly depends on the implementation of your spritesheet animation. If you want to implement it yourself, check out the SpriteBatch overload that lets you specify the rectangle of the texture to sample from. You can use that to pick the right frame from the spritesheet. Or you could use an existing implementation of course.

Another quick question, would you happen to know how to make the collectible asset sprite disappear upon collision with the player character? It won’t be animated.

You’ll probably have a list of collectibles in your level/scene class (or just in Game1). You can loop over that list, check if the boundingbox of that Collectible overlaps with your player boundingbox (there’s a method for that, Rectangle.Overlaps or something but I’m not sure about the name) and if it does remove it from the list. Make sure you loop over the list backwards by index so you can remove elements without messing up.

There’s a platformer sample game that will really help you out: https://github.com/MonoGame/MonoGame.Samples/tree/develop/Platformer2D
I don’t think the collectibles are animated, but there’s a lot of other stuff you can learn from it.