Skip to content

Sprite

Billboarded quad that always faces the active camera.

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.

cpp
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()

cpp
vglx::Sprite::Sprite(std::shared_ptr< SpriteMaterial > material)
ParameterDescription
materialMaterial used to render the sprite (may be null).

Constructs a sprite with an optional material. If material is null, a new instance of SpriteMaterial will be created.

Factories preferred


Sprite::Create() auto

cpp
static auto vglx::Sprite::Create(std::shared_ptr< SpriteMaterial > material=nullptr)
ParameterDescription
materialShared pointer to a sprite material.

Creates a shared pointer to a Sprite object with material.

Properties

anchor Vector2

cpp
Vector2 anchor { 0.5f, 0.5f }

Normalized anchor point inside the sprite.

rotation float

cpp
float rotation { 0.0f }

View-space rotation angle in radians applied to the sprite.

Functions

GetMaterial() std::shared_ptr<Material>

cpp
std::shared_ptr< Material > vglx::Sprite::GetMaterial() override

Returns the material associated with the sprite.

GetNodeType() Node::Type

cpp
Node::Type vglx::Sprite::GetNodeType() const override

Returns node type.

SetMaterial() auto

cpp
auto vglx::Sprite::SetMaterial(std::shared_ptr< SpriteMaterial > material)
ParameterDescription
materialShared pointer to a sprite material.

Sets the material used to render the sprite.

Released under the MIT License.