Sprite - Horizon-NTH/HorizonGUI GitHub Wiki

Sprite

Overview

The Sprite class, located in the hgui::kernel namespace, represents a graphical element that displays an image or texture. Sprites are commonly used to render images, textures, or icons within your graphical application. This class extends the Widget class and allows you to create and manipulate sprites with various properties, such as size, position, color, and texture. The class can be found in the header file Sprite.h.

Constructors

  • Sprite(const std::shared_ptr<Shader>& shader, const std::shared_ptr<Texture>& texture, const size& size, const point& position, const color& color, float rotation): Constructs a Sprite object with the specified shader, texture, size, position, color, and a rotation.

Member Functions

  • const std::shared_ptr<Texture>& get_texture() const: Retrieves the sprite texture.

  • void set_texture(const std::shared_ptr<Texture>& newTexture): Sets a new texture for the sprite, allowing you to change the image or texture displayed.

  • const color& get_color() const: Retrieves the sprite color.

  • void set_color(const color& newColor): Sets a new color for the sprite.

  • HGUI_PRECISION get_rotation() const: Retrieves the sprite rotation.

  • void set_rotation(HGUI_PRECISION rotation): Sets a new rotation for the sprite.

Example Usage

#include <hgui/header/Sprite.h>

// Example Usage of Sprite class
std::shared_ptr<hgui::kernel::Shader> shader = /* initialize shader */;
std::shared_ptr<hgui::Texture> texture = /* initialize texture */;

hgui::kernel::Sprite sprite(shader, texture, hgui::size(100, 100), hgui::point(300, 300), hgui::color(1.0f, 1.0f, 1.0f), 0.0f);

// Set the position of the sprite
sprite.set_position(hgui::point(400, 400));

// Set a new texture for the sprite
std::shared_ptr<hgui::Texture> newTexture = /* initialize new texture */;
sprite.set_texture(newTexture);

// Draw the sprite
sprite.draw();

Note: In the "Example Usage" section, we demonstrate how to create a Sprite object with a shader, texture, size, position, color, and angular rotation. You can set the position of the sprite, change the texture, and draw the sprite to display it within your graphical application. This class is ideal for rendering images and textures in your user interface.

⚠️ **GitHub.com Fallback** ⚠️