Skip to content

Instantly share code, notes, and snippets.

@luigi-rosso
Created July 17, 2020 18:44
Show Gist options
  • Save luigi-rosso/b2085f65f6c8dcb2fe5ccfe7b537ab92 to your computer and use it in GitHub Desktop.
Save luigi-rosso/b2085f65f6c8dcb2fe5ccfe7b537ab92 to your computer and use it in GitHub Desktop.
Color Changing Controller for Rive 2
class ColorChangingController extends SimpleAnimation {
final Set<Fill> fills = {};
ColorChangingController(String animationName) : super(animationName);
@override
bool init(Artboard artboard) {
if (!super.init(artboard)) {
return false;
}
// Crappy way to find the right components, we need to add an
// artboard.get('name');
artboard.forEachComponent((component) {
if (component.name == 'liquid_back' || component.name == 'liquid_front') {
if (component is Shape) {
// It's a shape as expected grab the fills and store them so we can
// later manipulate their color values.
fills.addAll(component.fills);
}
}
});
return true;
}
Color get color {
for (final fill in fills) {
var painter = fill.paintMutator;
if (painter is SolidColor) {
return painter.color;
}
}
return null;
}
set color(Color value) {
for (final fill in fills) {
var painter = fill.paintMutator;
if (painter is SolidColor) {
painter.color = value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment