Sprite Manager - Horizon-NTH/HorizonGUI GitHub Wiki
SpriteManager
Overview
The SpriteManager
class, located in the hgui
namespace, provides
management of Sprites
and AnimatedSprites
in your graphical application.
The class can be found inside the header file SpriteManager.h
.
Member Functions
-
std::shared_ptr<kernel::Sprite> create(const std::variant<std::shared_ptr<kernel::Texture>, std::shared_ptr<kernel::Image>>& texture, const size& size, const point& position, const color& color = HGUI_COLOR_WHITE, float rotation = 0.0f)
: Creates a new sprite by specifying a texture or image, size, position, color, and a rotation. -
std::shared_ptr<kernel::AnimatedSprite> create(const std::shared_ptr<kernel::GIF>& gif, const size& size, const point& position, const color& color = HGUI_COLOR_WHITE, float angularRotation = 0.0f)
: Creates a new animated sprite by specifying a gif, size, position, color, and angular rotation.
Example Usage
#include <hgui/header/SpriteManager.h>
{ // Example Usage of SpriteManager
std::variant<std::shared_ptr<hgui::kernel::Texture>, std::shared_ptr<hgui::kernel::Image>> texture = /* initialize texture or image */;
hgui::size spriteSize(64, 64);
hgui::point spritePosition(100, 100);
hgui::color spriteColor = HGUI_COLOR_WHITE;
float spriteRotation = 45.0f;
// Create a sprite
std::shared_ptr<hgui::kernel::Sprite> customSprite = hgui::SpriteManager::create(texture, spriteSize, spritePosition, spriteColor, spriteRotation);
std::shared_ptr<hgui::kernel::GIF> gif = = /* initialize your gif */
// Create an animated sprite
std::shared_ptr<hgui::kernel::AnimatedSprite> customAnimatedSprite = hgui::SpriteManager::create(gif, spriteSize, spritePosition, spriteColor, spriteRotation);
customAnimatedSprite->play(); // Initialize the playback of the gif
// Use the sprite as needed
// (Render objects using the custom sprite here)
} // Here the custom sprite and animated sprite are destroyed
Note: In the "Example Usage" section, we demonstrate how to create a custom sprite and an animated sprite with the
SpriteManager
class.