Dragon song – animations using Thor
|
With the alpha completed we began the work on the beta. I have mainly worked with the implementation of animation in our game. This blog posts will be about that topic. Previously to this week I had never animated from a programmers point of view, I have had some very inconsequential experience with animating in flash. When I researched how to animate using SFML I found out about a library extension called Thor. From reading the documentation I saw some functionalities that could be useful in our project, so after asking a second year student if he thought Thor could be of use for us I decided to try to implement it. To use Thor in our project I first had to install Thor with the program CMake, and then compile it visual studio and finally link it with the project. This took some tinkering but after some time it worked. The main reason I wanted to use Thor, other than its fun to learn new things, was that it included already made functions I could use to easier create animations with easy to read code. Later in the project when for example the player character receives more animations Thor has functions to easy switch between them, another reason I thought it worth to try it. I will take on of the enemies as an example on how the animation code looks. Here is how the sprite sheet looks:
In the enemy.cpp the sprite sheet is set loaded from a file and then set to a sprite. Using thor::FrameAnimation the coordinates are set from the sprite sheet. We have different looking enemies in the game that is spawned using a txt file. Every enemy sprite sheet is created to have the same coordinates and consist of eight frames of an animation. This in combination of how the code is used allows for every enemy to use the same animation function, only with different sprite sheets. Example: m_animation.addFrame(1.f, sf::IntRect(256, 0, 256, 256)); m_animator->playAnimation(”idle”, true); m_animator->animate(*m_sprite); In the GameState the animation is updated and the animation starts when an enemy is spawned.
Here is a link to the Thor website : http://www.bromeon.ch/libraries/thor/v2.0/doc/index.html. I have only used Thor for animations yet, but I might look if there are additional classes that could be useful for our project. |