First post
|
The artifact that i have focused on this week is the AnimatedTexture. This artifact is a class that makes it possible to add an animation to an object instead of just a static image. Animated images is something that will be used heavily in the game and this is how i did it. When creating an AnimatedTexture I pass one argument which is the image file location to the constructor. Then I call the AddFrame function in the created AnimatedTexture and which takes five arguments that are put into a struct. The first four are stored in a sf::IntRect to be used when I only want a part of the picture file that is loaded. The values passed are A X coordinate , An Y coordinate, Width, Height and Duration. The X and Y coordinates is the position on the picture that the texture should start. Then you add the Width and Height of the texture and lastly Duration that determines for how long the frame will be shown. I call AddFrame for every frame that I want to create. After that I pass the AnimatedTexture into the object that will use it. When the object is updated it will call for the Update function of the AnimateTexture and passes the time that has gone since the last update. The function adds that time onto a variable and if that variable is larger than the duration of the frame, it is set to 0 and the frame is updated to the next frame. The objects then gets the texture and the region and updates the sprite it has. During my work of this artifact i found some problems after being used to work with SDL during the last course. The biggest one was that textures and sprites are handled in different ways. I had a problem that i were trying to figure out for far too long when i tried to get the current texture in the AnimatedTexture so that i could update the sprite with that texture however it did not show up. I assumed that the file did not load but that only led me astray and after a bit of research i found that i was getting the value of the texture but the thing i needed was the address. The reason for me to do it in this way is because I used the same principles when i made my first project last period. I wanted to make something that i was comfortable with using and that i knew worked.
|
