Sprite
Sprite is a flat, unit-sized quad oriented toward the camera at all times. It is usually textured (often with transparency) and exposes the minimal Renderable interface so it can be submitted to the renderer.
Common use cases include particles, labels, icons, and world-space markers.
auto MyNode::OnAttached(SharedContextPointer context) -> void override {
context->texture_loader->LoadAsync(
"assets/sprite.tex",
[this](auto result) {
if (result) {
auto mat = vglx::SpriteMaterial::Create();
mat->albedo_map = result.value();
auto sprite = Sprite::Create(mat);
sprite->SetScale(0.5f);
Add(sprite);
} else {
std::println(stderr, "{}", result.error());
}
}
);
}Construction
Constructors
Sprite()
Constructs a sprite with an optional material.
If material is null, a new instance of SpriteMaterial will be created.
Sprite::Sprite(std::shared_ptr<SpriteMaterial> material);| Parameter | Description |
|---|---|
| material | Material used to render the sprite (may be null). |
Factories preferred
Sprite::Create() auto
Creates a shared pointer to a Sprite object with material.
static auto Sprite::Create(std::shared_ptr<SpriteMaterial> material=nullptr);| Parameter | Description |
|---|---|
| material | Shared pointer to a sprite material. |
Properties
Normalized anchor point inside the sprite. Defines the pivot used for placement and rotation of the sprite.
(0.0f, 0.0f) = lower-left corner of the sprite.(0.5f, 0.5f) = center of the sprite (default).(1.0f, 1.0f) = upper-right corner of the sprite.
The sprite's world-space position corresponds to this anchor point. Rotation is applied around this pivot.
Vector2 anchor {Vector2 {0.5f, 0.5f}};rotation float
View-space rotation angle in radians applied to the sprite.
float rotation {0.0f};Functions
Returns the material associated with the sprite.
std::shared_ptr<Material> Sprite::GetMaterial() override;GetNodeType() Node::Type
Returns node type.
Type vglx::Sprite::GetNodeType() const override;SetMaterial() auto
Sets the material used to render the sprite.
auto Sprite::SetMaterial(std::shared_ptr<SpriteMaterial> material);| Parameter | Description |
|---|---|
| material | Shared pointer to a sprite material. |