Implementation of Animation Code
|
This week I have mostly been implementing animation for several sprites and special effects, using an animation code I made beforehand. I have previously used this code only to switch singular frames on sprites, but, as I am aware of now, it is a bit more difficult to cycle through animation frames using this code unless they are in a specific order. Overall, the function is fairly simple and looks something like this: inline void Animation(sf::Sprite* p_sprite, sf::Vector2i p_vectorI, int p_xMin, int p_xMax, int p_yMin, int p_yMax, int p_width, int p_height)
The function muliplicates the values of sf::Vector2i p_vectorI in x-axis and y-axis with the width and height of the frame, respectively, then checks if they are above or below the maximum allowed size, then sets the TextureRect of the sprite to the mulitplicated value. It is of course arguable if the min/max values of frames’ size really are necessary, as the code is relatively simple and requires a lot of additional parameters. For example; as I implemented the animation for the player’s sprite, I bumped into the first problem with the function: The sprite needed to cycle between three frames if it turned and cycle through roughly four frames when it fired. The frames for turning were seperated from their respective frames for firing, meaning that to animate the firing correctly, my function would first have to ”jump” to the second frame of each firing animation, then cycle through them, ending by jumping back to the respective turning frame. As this was a bit problematic to accomplish, I decided to switch the positions of the frames of the spritesheet so that each five frame animation were on a row by each other.
|

