On flutter flame 1.0.0 how to use the onComplete callback when move effect is over?

120

Unfortunately they don't exist yet in Flame 1.0.0.

The onFinishCallback is merged to main though, so you can depend on main to get that behaviour, or wait until we release it.

To Depend on main, put this in your pubspec.yaml file.

dependencies:
  flame:
    git:
      url: https://github.com/flame-engine/flame.git
      ref: main
      path: packages/flame

speed for the MoveEffect is being worked on, but it is not done yet. A workaround, if you are passing in a Path to the MoveEffect, is to calculate the duration from the speed and length of the path:

final speed = 10; // Pixels per second
List<PathMetric> metrics = path.computeMetrics().toList();
double pathLength = 0;
pm.forEach((contour){
  pathLength += contour.length;
});
final duration = pathLength / speed;

It's quite a cumbersome work-around so I hope that we'll release speed for the MoveEffect soon!

Share:
120
Eli dp
Author by

Eli dp

Updated on January 02, 2023

Comments

  • Eli dp
    Eli dp over 1 year

    I was using the onComplete callback on previous flame engine version in move effect but now that version 1.0.0 was released I can’t manage to find it although it is mentioned in the documentation but not clearly and there is no example for it.

    Another missing part is defining moving effect with speed instead of duration - do I need to calculate it manually? Or there is an option to provide it (I am using move.to method)