update method
Called before a frame is drawn.
Override this method to do any updates to the node or node tree before it's drawn to screen.
// Make the node rotate at a fixed speed
void update(double dt) {
rotation = rotation * 10.0 * dt;
}
Implementation
@override
void update(double dt) {
// Update scrolling position
if (animationMode == EffectLineAnimationMode.scroll) {
_offset += dt * scrollSpeed;
_offset %= 1.0;
} else if (animationMode == EffectLineAnimationMode.random) {
_offset = randomDouble();
}
// Update age of line points and remove if neccesasry
if (fadeDuration != null && fadeAfterDelay != null) {
// Increase age of points
for (int i = _points.length - 1; i >= 0; i--) {
_pointAges[i] += dt;
}
// Check if the first/oldest point should be removed
while (_points.isNotEmpty &&
_pointAges[0] > (fadeDuration! + fadeAfterDelay!)) {
// Update scroll if it isn't the last and only point that is about to
// removed
if (_points.length > 1 && textureLoopLength != null) {
double dist = GameMath.distanceBetweenPoints(_points[0], _points[1]);
_offset = (_offset - (dist / textureLoopLength!)) % 1.0;
if (_offset < 0.0) _offset += 1;
}
// Remove the point
_pointAges.removeAt(0);
_points.removeAt(0);
}
}
}