Animations
|
Magic writer is a game concept me and a group of other people are developing. In this you play as a magician that has a holiday on a tropical beach. Unfortunately he is interrupted by monster invading the beach. Ah no holiday this time. The magician is skilled in summoning magic. So he uses this to summon objects and throwing them with magic on the monsters. By doing this the monsters will be defeated and the oncoming tide halted. Summoning is done by typing in the word of the item displayed on the screen. The game would look dull and lifeless without things moving, instead of sparling with life and movement. So all entity classes (character, enemy, objects etc) had to be remade, since they used an sf::sprite (part of an image), and not an animated sprite that changes frames automatically. We use sfml in this project and it has no built in animation class but its homepage links to github (an opensource site, were people post code either for programs or library like sfml ) and it just so happens that a person has written a class for animation and animated sprite and posted it there. So i took this class and started to get to work, and a lot of work it was. First of transforming the classes so that they take in a animation, animated sprite in the beginning but changed due to this being unnecessary since it only take in one animation sprite and can not hold more. The animation class can only hold one animation per object, it takes in a specified number of frame and the texture (image loaded into the program), the frames specifies what part of the texture and size that should be used at the time. So with all of this almost in mind I started to reform the class after testing it in the game state, where I just made several animation objects and switched which one the animated sprite should use. Animation class had a std::vector that held an integer rect that contained all the frames of the animation, this was the starting point since I wanted to make the animation hold several animations I made a std::map hold a string and std::vector with intrects, the string to be able to locate the animation it containing the name of it and the vector as before. A vector containing all the names as well so one could get access to them or easily compare them. And a integer variable to mark which animation is active. There would also have to be changes to the methods of the class so that instead of taking in an intrect a whole std::vector containing the intrects for a single animation. A function for returning the animation names, as well as one for the active one so that one can check if the that is active is active or similar. Then a lot of more changes ha to be made to make the whole thing work. A set active animation had to be added and that takes in the name of the animation you want to change to and then has to search through the map and try to find it, if not found nothing happens, if found it changes to that and sets the active one to the position in the string vector of the name. Made some more changes. Eventually remembered that the animated sprite uses a time variable for how long a frame should be active and it is the same for all the frames, so if one wants to be able to have a specific time for each frame I figured that the animation should take in a sf::time variable, changed though till making the intrect and time to a pair and placing them in the variable that you enter in the add frame function(method). This complicated things a bit but I finally managed to fix it, the animated sprite then takes in the pair when collecting a frame from the animations and puts the member time variable to the time from animation, this allows me top put a time in for example a text document and loading it into the program, where I can easily change it compared to if I always has to change it in the program. Minor changes where made to the animated sprite class compared to the animation class. Overall this process went all right and I now have a functioning animation class in the game and felt it well worth the effort. The changed classes: AnimatedSprite,cpp AnimatedSprite Animation,cpp Animation |


