How can you animate sprite in SFML

Suppose I have 4 images and I want to use these 4 images to animate a character. These 4 images represent a character walking. I want the animation to repeat while I press a key to move, but to stop when I do not delete it. It doesn't have to be SFML if you don't know it, only the basic theory will really help me.

Thank.

+5
source share
1 answer

You may need some simple state apparatus. When the key is unavailable (see sf :: Input IsKeyDown method ), enter the character in the "animated" state. When the key is not lowered, the character must be in a "not animated" state. Of course, you can always skip this “state” and just do what I mention below (depending on what you are doing).

, "" , "" ( . ). , , 4- , (currentIndex + 1) % ARRAY_SIZE. , , . "" , .

"4 " , sf:: Sprite SetSubRect, . 4 , , , sf:: Sprite SetImage .

+10

All Articles