Jetpack documentation 1.0.0
Loading...
Searching...
No Matches
Animation.hpp
1/*
2** EPITECH PROJECT, 2025
3** jetpack
4** File description:
5** The Animation.hpp
6*/
7
8#ifndef ANIMATION_HPP_
9 #define ANIMATION_HPP_
10
11 #include "utils/Jetpack.hpp"
12 #include <SFML/Audio/Music.hpp>
13 #include <SFML/Graphics/RectangleShape.hpp>
14 #include <SFML/Graphics/Texture.hpp>
15 #include <SFML/Graphics.hpp>
16 #include <SFML/Audio/Sound.hpp>
17 #include <SFML/Graphics/Sprite.hpp>
18 #include <SFML/System/Vector2.hpp>
19 #include <SFML/Window/Keyboard.hpp>
20 #include <SFML/Audio.hpp>
21
22namespace Jetpack {
27 class Animation {
28 public:
29 /* Constructor and destructor */
30
35 Animation(sf::Vector2u textureSize = {0, 0});
39 ~Animation();
40
41
42
43 /* The animation functions */
44
49 void setTextureSize(sf::Vector2u textureSize);
61 bool addAnimation(const std::string& name, int frameCount, sf::Vector2u frameSize, sf::Vector2u startPosition,float fps = 12.0f, bool loop = true);
69 bool setCurrentAnimation(const std::string& name, bool resetFrame = true);
74 void update(float deltaTime);
78 void play();
82 void pause();
86 void stop();
91 bool isPlaying() const;
96 std::string getCurrentAnimationName() const;
101 void setFlipX(bool flip);
106 void setFlipY(bool flip);
111 const sf::IntRect& getTextureRect() const;
112
113 private:
118 std::string name; /* Name of the animation */
119 int frameCount; /* Number of frames in the animation */
120 sf::Vector2u frameSize; /* Size of each frame */
121 sf::Vector2u startPosition; /* Starting position of the animation in the sprite sheet */
122 float frameDuration; /* Duration of each frame in seconds */
123 bool loop; /* Whether the animation should loop */
124 };
129 void updateTextureRect();
130
131
132
133 private:
134 sf::IntRect _textureRect; /* The texture rectangle for the current frame */
135 sf::Vector2u _textureSize; /* Size of the texture */
136 std::unordered_map<std::string, AnimationData> _animations; /* Map of animations (name, AnimationData) */
137 std::string _currentAnimationName; /* Name of the current animation */
138 int _currentFrame; /* Current frame index */
139 float _timeAccumulator; /* Time accumulator for frame duration */
140 bool _isPlaying; /* The playing status of the animation */
141 bool _flipX; /* The flip status of the animation on the X axis */
142 bool _flipY; /* The flip status of the animation on the Y axis */
143 };
144}
145
146#endif /* ANIMATION_HPP_ */
The Jetpack.hpp.
A class that handles sprite animations.
Definition Animation.hpp:27
const sf::IntRect & getTextureRect() const
Gets the texture rectangle for the current frame.
Definition Animation.cpp:241
bool isPlaying() const
Checks if the animation is playing.
Definition Animation.cpp:156
bool setCurrentAnimation(const std::string &name, bool resetFrame=true)
Sets the current animation.
Definition Animation.cpp:77
std::string getCurrentAnimationName() const
Gets the current animation name.
Definition Animation.cpp:165
void setTextureSize(sf::Vector2u textureSize)
Sets the texture size for the animation.
Definition Animation.cpp:34
void play()
Plays the current animation.
Definition Animation.cpp:128
void pause()
Pauses the current animation.
Definition Animation.cpp:136
bool addAnimation(const std::string &name, int frameCount, sf::Vector2u frameSize, sf::Vector2u startPosition, float fps=12.0f, bool loop=true)
Adds an animation to the animation list.
Definition Animation.cpp:50
void setFlipX(bool flip)
Sets whether the sprite should be flipped horizontally.
Definition Animation.cpp:174
void stop()
Stops the current animation and resets it.
Definition Animation.cpp:144
void updateTextureRect()
Updates the texture rectangle for the current frame.
Definition Animation.cpp:198
void setFlipY(bool flip)
Sets whether the sprite should be flipped vertically.
Definition Animation.cpp:186
Animation(sf::Vector2u textureSize={0, 0})
Constructor for Animation class.
Definition Animation.cpp:15
void update(float deltaTime)
Updates the animation based on elapsed time.
Definition Animation.cpp:101
~Animation()
Destructor for Animation class.
Definition Animation.cpp:25
Structure to store animation data.
Definition Animation.hpp:117