AnimationCycle - VictorAlvizo/Ventura GitHub Wiki
The AnimationCycle class is a way to make animations using a spritesheet, mainly by getting the index needed at that time for the SpriteSheetReader class to use.
This is the default constructer for the class, it initializes just two variables and that's it.
The copy constructer for the AnimationCycle is needed as this class uses multi-threading. std::mutex
cannot be copied thus the reason why a custom copy constructer had to be written
The deconstructer, again just resets two variables
- Name to represent the new animation sequence, if another sequence with that same name already exists it will be overwritten
- The starting x position of the sequence in relation to the spritesheet
- The ending x position of the sequence in relation to the spritesheet
- the y represents the row that will remain constant in relation to the spritesheet.
- The speed of the animation measured in miliseconds. How many miliseconds the the class should wait until moving on to the next frame. The shorter the number, the faster the frames will change. Set to 100 by default
- Set to true if the sequence should loop or false so it only plays the animation sequence once. Set to default as true
When dealing with a spritesheet that has the frames going horizontally this is useful as by only giving it the starting and ending index of a specifed row it will have the indexes required for that sequence.
Example:
LinearX("Walking", 0, 4, 7, 150, true)
Make a walking animation which is to be referred to as "Walking" that starts from the 0 x to 4 x on the 7th row. The animation should change frames every 150 miliseconds, and the animation should loop
- Name to represent the new animation sequence, if another sequence with that same name already exists it will be overwritten
- The starting y position of the sequence in relation to the spritesheet
- The ending y position of the sequence in relation to the spritesheet
- the x represents the column that will remain constant in relation to the spritesheet.
- The speed of the animation measured in miliseconds. How many miliseconds the the class should wait until moving on to the next frame. The shorter the number, the faster the frames will change. Set to 100 by default
- Set to true if the sequence should loop or false so it only plays the animation sequence once. Set to default as true
When dealing with a spritesheet that has the frames going vertically this is useful as by only giving it the starting and ending index of a specifed column. It will have the indexes required for that sequence.
Example:
LinearY("Fall", 2, 3, 3, 500, false)
Make a falling animation which is to be referred to as "Fall" that starts from the 2 y to 3 y on the 3th row. The animation should change frames every 500 miliseconds, and the animation should not loop
void CustomCycle(const std::string cycleName, std::vectorglm::ivec2 spritePoses, int speed, bool loop)
- Name to represent the new animation sequence, if another sequence with that same name already exists it will be overwritten
- The custom indexes of the sprite in relation to the spritesheet
- The speed of the animation measured in miliseconds. How many miliseconds the the class should wait until moving on to the next frame. The shorter the number, the faster the frames will change. Set to 100 by default
- Set to true if the sequence should loop or false so it only plays the animation sequence once. Set to default as true
What if the spritesheet does not follow any order and the sprites are all over the place that a sequence can not be obtained linearly? This is where this comes in handy; as you're able to specify want indexes make up an animation sequence.
Example:
CustomCycle("WalkFallFusion", { glm::ivec2(0, 2), glm::ivec2(0, 4) }, 40, false);
In this example I want to combine 2 sprites together that aren't adjacent to eachother, so I call CustomCycle to make a sequence using my custom positions.
- The name of the sequence you want to animate
Once you have an animation sequence ready call it by it's name and it will begin setting the indexes for that animation. If a name is called that does not exist in the sequence it will prompt an error and nothing will happen. If it is told to run an animation that is currently running it will ignore the call. If an animation that does not loop is currently ongoing and you call in another animation that request will be discareded. If those cases don't happen and all goes normally, it will set the new animation cycle going. If it's the classes first time running that animation or the an animation has forcefully been stopped prior and a new one is getting started, it will initate a new thread to run to retrive animation indexes for spritereader to use.
Returns a 2D int vector with the current sprite position that is to be used by the SpriteSheetReader class. This function is to be called whenever you want to retrieve the current sprite in the animation cycle in coordination with the SpriteSheetReader's getTexUV()
method.
Returns the name of the current animation cycle playing
If this is set to = false when an animation cycle is ongoing it will stop the animation and the kill the animation thread. Way to stop an animation. Setting it back to true won't restart the animation and instead you will have to call Animate()
to restart the animation.