I need to do some calculations between every update()
, so I need to ensure that a function is processed before the next frame.
Is there any way to achieve this? Just like "WaitForEndOfFrame" in Unity?
You can override the updateTree
in your FlameGame
(or in your Component
, if you only want it to happen before the update
s of a subtree) and do your calculations right before all the other components start updating. This would be right after the last frame, except for the first frame, but that one you can skip by setting a boolean.
So something like this:
class MyGame extends FlameGame {
bool isFirstTick = true;
@override
void updateTree(double dt) {
if(!isFirstTick) {
// Do your calculations
} else {
isFirstTick = false;
}
super.updateTree(dt);
}
}
But I have to ask, why do you need to do this? render
won't be called until all the update
calls are done, do can't you just put your calculations in the normal update
method?