Update animation properties dynamically
masterrlottie allows you to modify animation properties (like colors or opacity) at runtime using setValue<rlottie::Property>(). This is useful for theming or responding to events.
To use setValue, you need:
- KeyPath: A string representing the hierarchy of the object (e.g.,
"Layer1.Box 1.Fill1"). Supports wildcards:*: Matches any single content name in that position.**: Globstar that matches zero or more layers.
- Property: An element from the
rlottie::Propertyenum (e.g.,FillColor,StrokeOpacity). - Value: A constant value (like
rlottie::Color) or a callback function that acceptsrlottie::FrameInfoto return a value that changes per frame.
// Set a constant color for all layers using a globstar
animation->setValue<rlottie::Property::FillColor>("**", rlottie::Color(0, 1, 0));
// Set a color that changes based on the current frame
animation->setValue<rlottie::Property::FillColor>("Layer1.Box 1.Fill1",
[](const rlottie::FrameInfo& info) {
if (info.curFrame() < 15 )
return rlottie::Color(0, 1, 0);
else {
return rlottie::Color(1, 0, 0);
}
});