onPostUpdate method
Override to react after the update phase each frame.
Called after all registered listenOnPostUpdate listeners.
Implementation
@override
void onPostUpdate(double dt) {
final screen = sceneBounds.size;
scene.QueryEntity.DoForEachWith2<CTransform<T>, CVelocity<T>>((e, t, v) {
final bounds = e.bounds;
if (bounds == null) return;
final pos = t.position;
final vel = v.velocity;
final body = e.get<CPhysicsBody<T>>();
final isKinematic = body != null && body.mass == 0;
double rx = bounds.width / 2;
double ry = bounds.height / 2;
// TOP
final minY = ry;
if (top && pos.y < minY) {
pos.y = minY;
if (vel.y < 0) vel.y = isKinematic ? 0 : -vel.y * restitution;
}
// LEFT
final minX = rx;
if (left && pos.x < minX) {
pos.x = minX;
if (vel.x < 0) vel.x = isKinematic ? 0 : -vel.x * restitution;
}
// BOTTOM
final maxY = screen.y - ry;
if (bottom && pos.y > maxY) {
pos.y = maxY;
if (vel.y > 0) vel.y = isKinematic ? 0 : -vel.y * restitution;
}
// RIGHT
final maxX = screen.x - rx;
if (right && pos.x > maxX) {
pos.x = maxX;
if (vel.x > 0) vel.x = isKinematic ? 0 : -vel.x * restitution;
}
});
}