How does one animate sprites?

I’ve been trying to create an animation system for my game, however; whenever I re-assign the player’s texture in order to draw the new frame’s texture, the previous frame’s texture remains on the screen.

I’ve been experimenting with different solutions for a few hours, but I haven’t really found a solution that works properly.

Also; is there a way to create animations that doesn’t require me to create a whole animation system from scratch?

Can you show some of your code

I use dragon bones and gimp to create a spritesheet, but you can use any of a hundred methods.

in the code,
I load a this whole spritesheet for my characters texture,
and create a rectangle (stencil-rectangle) fitting an animation frame.

in Update I update the stencil-rectangle position (X,Y) according to what the player is doing…

in Draw, i draw the spritesheet texture, but only the part within the stencil_rectangle, and I draw that bit of texture on my characters position, giving the illusion of smooth movement.

Could you show an example with code? Having a bit of trouble trying to wrap my head around the entire thing lol

Thanks for the reply though!

You should watch or read any of a million tutorials on how to setup an animation using a sprite sheet, it is a SUPER common technique, has been for decades.

You just update your source rectangle every time you want to switch to the next animation frame.

I don’t have a code that is good to paste, because my animation is very case specific…

Villatic, if you’re having trouble with your code it’s always a good idea to post the related code with your question. It’ll help with answering your question; especially since not all solutions may fit your needs.

However, I’d recommend putting your sprites in a texture atlas. Then in your code, your source rectangle can be changed to pick the corresponding frame of animation. But again, seeing the code for your problem will help us supply a corresponding solution that fits your needs.

Hmmmm I slept on the issue and I think I can come up with a solution regarding the rectangle.