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 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 material = vglx::SpriteMaterial::Create();
        material->albedo_map = result.value();

        Add(Sprite::Create(material))->SetScale(0.5f);
      } else {
        std::println(stderr, "{}", result.error());
      }
    }
  );
}

Construction

Constructors


Sprite()

Constructs a sprite.

If material is null a new instance of SpriteMaterial will be created.

cpp
Sprite::Sprite(std::shared_ptr<SpriteMaterial> material);
ParameterDescription
materialMaterial used to render the sprite.

Factories preferred


Sprite::Create() std::unique_ptr<Sprite>

Creates an instance of Sprite.

cpp
static std::unique_ptr<Sprite> Sprite::Create(std::shared_ptr<SpriteMaterial> material=nullptr);
ParameterDescription
materialShared sprite material.

Properties

anchor Vector2

Normalized anchor point inside the sprite. Defines the pivot used for placement and rotation of the sprite.

  • lower-left corner of the sprite.
  • center of the sprite (default).
  • upper-right corner of the sprite.

The sprite's world-space position corresponds to this anchor point. Rotation is applied around this pivot.

cpp
Vector2 anchor {Vector2 {0.5f, 0.5f}};

rotation float

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

cpp
float rotation {0.0f};

Functions

GetMaterial() std::shared_ptr<Material>

Returns the material associated with the sprite.

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

GetNodeType() Node::Type

Identifies this node as.

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

SetMaterial() auto

Sets the material used to render the sprite.

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

Released under the MIT License.