|
Even though it was long time ago they were made (like 5 weeks), I think it is time to talk some about them.
Both the guards and the player have a lot of different animations.
For example, the player has:
- Sneak
- Run
- Idle
- Dying
- Attack
- Strafing
- Walking
And the guards have:
- Draw weapon
- Walk

- Run
- Idle
- Smoke
- Falling

- Rising
Shooting
And instead of asking the Sprite Manager for a new animation each time it needs to change it, each Animated Sprite holds pointers to each animation instead. So, all that is needed to change from one animation to any other is to tell the Animated Sprite which to switch to and it will search through all its animations and change the current animation to the new one.
The Sprite Manager is managing the textures, so maybe I should have named it Texture Manager instead. I think that would have been a more accurate description of what its main purpose does.
Its primary function is to make sure that the same texture is not loaded twice. When it is asked for an animation or sprite, it looks through all the previously loaded textures. If it finds another texture loaded from the same image-file, it will return a pointer to that texture. If it is not found, it will load the new texture and return a pointer to that new texture.
When the game changes state, it will release all the memory of the textures, so that it doesn’t hold them when they are not needed.
When an entity asks for an Animated Sprite, the Sprite Manager needs to know which text-file to look for. In this text-tile, all the necessary data for all that entities animations are stored. Like which picture to load, each frames duration, at which coordinates each frame starts, and its width and height.
The text is which image it should load. The first number is that frames duration. Second and third are x- and y-coordinate of the upper left of that frame. Fourth and fifth are width and height for that frame.
It would look something like this in the text file:
Guard1Running.png
0.1 0 0 96 96
0.1 96 0 96 96
0.1 192 0 96 96
0.1 288 0 96 96
Guard1Shooting.png
0.2 0 0 96 96
0.2 96 0 96 96
0.2 192 0 96 96
0.2 288 0 96 96
Guard1Searching.png
0.2 0 0 96 96
0.2 96 0 96 96
0.2 192 0 96 96
0.2 288 0 96 96
The Sprite Manager is then using this information to create an Animated Sprite. When it has come to the end of the text file it will return a pointer to the Animated Sprite it just created.
By doing it this way it is easy to add new animations to, for example, the guards. All that is needed is a new sprite sheet with the frames, and then add the information for that animation at the end of the text file. Then, that guard just have to call the function ChangeAnimation(std::string animationName), that is part of Animated Sprite, to start using the new animation.

|