Sprite
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.
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.
Sprite::Sprite(std::shared_ptr<SpriteMaterial> material);| Parameter | Description |
|---|---|
| material | Material used to render the sprite. |
Factories preferred
Creates an instance of Sprite.
static std::unique_ptr<Sprite> Sprite::Create(std::shared_ptr<SpriteMaterial> material=nullptr);| Parameter | Description |
|---|---|
| material | Shared sprite material. |
Properties
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.
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() const override;GetNodeType() Node::Type
Identifies this node as.
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. |