shake method
void
shake({
- required WaitEvents wait,
- double time = 0.1,
- double amount = 2,
- bool slowlyHalt = false,
Implementation
void shake(
{required WaitEvents wait, double time = 0.1, double amount = 2, bool slowlyHalt = false}) {
if (shaking) return;
shaking = true;
final beforePos = position.clone();
wait.waitAndDo(
time: time,
onUpdate: (deltaTime, remaining) {
final ratio = slowlyHalt ? (remaining / time) : 1;
final amt = amount * ratio;
position.x += MathUtils.randDouble(-amt, amt);
position.y += MathUtils.randDouble(-amt, amt);
},
onEnd: () {
position.setFrom(beforePos);
shaking = false;
},
);
}