containsEventHandlerAt method
Whether the game has an event-handling component at the given position.
Used by GameRenderBox for hit testing to determine if pointer events
should be consumed by the game or passed through to Flutter widgets
behind it.
The default returns true, meaning games that directly extend Game
will catch all events on their entire surface. FlameGame overrides this
to only report a hit when a component with event callbacks
(e.g. TapCallbacks) exists at the given position.
Implementation
@override
bool containsEventHandlerAt(Vector2 position) {
// Deprecated game-level detector mixins handle events for the entire
// game surface, so any in-bounds point is a hit.
// ignore: deprecated_member_use_from_same_package
if (this is TapDetector ||
this is SecondaryTapDetector ||
this is TertiaryTapDetector ||
this is DoubleTapDetector ||
this is LongPressDetector ||
this is VerticalDragDetector ||
this is HorizontalDragDetector ||
this is ForcePressDetector ||
this is PanDetector ||
this is ScaleDetector ||
this is MultiTapListener ||
this is MultiTouchDragDetector) {
return true;
}
for (final component in super.componentsAtPoint(position)) {
if (component is TapCallbacks ||
component is DragCallbacks ||
component is DoubleTapCallbacks ||
component is ScaleCallbacks ||
component is SecondaryTapCallbacks) {
return true;
}
}
return false;
}