Last Signal – Asset Implementation
|
This week I have been working on implementing the assets that are not taken care of in the Room System, such as music, sounds, menus and animations. The music and sounds are handled through a soundmanager that was used during a previous project and is simply being reused with some tweaking. Since we are using the SFML library for this project we have to rewrite some of the earlier code since in the previous project it was made to be used with the SDL library. This transition was fairly easy to accomplish though. The point of the soundmanager is so that several objects can use the same loaded soundfile without having to read the file for each separate object. This is done by creating pointers that the objects are given to carry and can use whenever a sound is needed to play. The manager also handles the dynamic memory allocation and deallocation so that the objects does not need the functionality to handle the dynamic allocation and deallocation. For the menus they consist of a background sprite as well as a marker sprite to indicate which option of the menu is currently selected. The functionality of the menus are simply a number that tracks the current selection. This number is increased or decreased by one for each step the player makes with either the up- or down-key and is used to determine what state the player will go to when the enter-key is pressed. For the animations we use a similar manager to the one that we have used for a previous project. However since that was made for SDL there was a need to rewrite some of the code such that it could be used with the SFML library, same as with the soundmanager. This took a bit more work than the soundmanager but after some time I managed to get it working. The animations work as following: The game reads a texture file that contains all of the frames for a object. By using rectangles it adds several sprites that are mapped to a string that represents the name for the animation. By doing it this way, an object can read several animations by only using a single file that contains the all the frames necessary instead of breaking them up. When the object has to show a specific animation it can call the correct frames by using the string that is associated with the animation. |
