Animated Sprite - Horizon-NTH/HorizonGUI GitHub Wiki
The AnimatedSprite
class, located in the hgui::kernel
namespace, is an extension of the Sprite
class,
designed specifically for handling animated sprites. Animated sprites are graphical elements that display a
sequence of images or frames. This class extends the functionality of the Sprite
class by introducing features for playing, pausing, stopping, and looping animated sequences and
use GIF
class as data. The class can be found in the header file AnimatedSprite.h
.
-
AnimatedSprite(const std::shared_ptr<Shader>& shader, const std::shared_ptr<GIF>& gif, const size& size, const point& position, const color& color, HGUI_PRECISION rotation)
: Constructs anAnimatedSprite
object with the specified shader, GIF, size, position, color, and a rotation.
-
const std::shared_ptr<GIF>& get_gif() const
: Retrieves the GIF associated with the animated sprite. -
void set_gif(const std::shared_ptr<GIF>& gif)
: Sets a new GIF for the animated sprite, allowing you to change the animated sequence. -
void play()
: Initiates the playback of the animated sequence. -
void pause()
: Pauses the playback of the animated sequence. -
void stop()
: Stops the playback of the animated sequence. -
void loop()
: Enables looping of the animated sequence. -
void stop_loop()
: Disables looping of the animated sequence. -
bool is_playing() const
: Indicates whether the animated sequence is currently playing. -
bool is_looping() const
: Indicates whether the animated sequence is set to loop.
#include <hgui/header/AnimatedSprite.h>
// Example Usage of AnimatedSprite class
std::shared_ptr<hgui::kernel::Shader> shader = /* initialize shader */;
std::shared_ptr<hgui::GIF> gif = /* initialize GIF */;
hgui::kernel::AnimatedSprite animatedSprite(shader, gif, hgui::size(100, 100), hgui::point(300, 300), hgui::color(1.0f, 1.0f, 1.0f), 0.0f);
// Set a new GIF for the animated sprite
std::shared_ptr<hgui::GIF> newGIF = /* initialize new GIF */;
animatedSprite.set_gif(newGIF);
// Play the animated sequence
animatedSprite.play();
// Pause the animated sequence
animatedSprite.pause();
// Stop the animated sequence
animatedSprite.stop();
// Enable looping of the animated sequence
animatedSprite.loop();
// Disable looping of the animated sequence
animatedSprite.stop_loop();
// Check if the animated sequence is playing
bool isPlaying = animatedSprite.is_playing();
// Check if the animated sequence is set to loop
bool isLooping = animatedSprite.is_looping();
Note: In the "Example Usage" section, we demonstrate how to create an
AnimatedSprite
object with a shader, GIF, size, position, color, and angular rotation. You can set a new GIF, play, pause, stop, loop, and check the playback status of the animated sequence. This class is ideal for handling animated sprites in your graphical application.