diff --git a/doc/other-inputs.md b/doc/other-inputs.md index 4690c887df3..c42e5f14d22 100644 --- a/doc/other-inputs.md +++ b/doc/other-inputs.md @@ -113,9 +113,9 @@ As the name suggests this button is a hud by default, which means that it will b screen even if the camera for the game moves around. You can also use this component as a non-hud by setting `hudButtonComponent.respectCamera = true;`. -If you want to act upon the button being pressed (which would be the common thing to do) you can either pass in -a callback function as the `onPressed` argument, or you extend the component and override -`onTapDown`, `onTapUp` and/or `onTapCancel` and implement your logic there. +If you want to act upon the button being pressed (which would be the common thing to do) and released, +you can either pass in callback functions as the `onPressed` and `onReleased` arguments, or you can +extend the component and override `onTapDown`, `onTapUp` and/or `onTapCancel` and implement your logic there. ## SpriteButtonComponent diff --git a/packages/flame/lib/src/components/input/hud_button_component.dart b/packages/flame/lib/src/components/input/hud_button_component.dart index 4246f9105bb..6698959e598 100644 --- a/packages/flame/lib/src/components/input/hud_button_component.dart +++ b/packages/flame/lib/src/components/input/hud_button_component.dart @@ -14,15 +14,21 @@ class HudButtonComponent extends HudMarginComponent with Tappable { late final PositionComponent? buttonDown; /// Callback for what should happen when the button is pressed. - /// If you want to interact with [onTapUp] or [onTapCancel] it is recommended - /// to extend [HudButtonComponent]. + /// If you want to directly interact with [onTapUp], [onTapDown] or + /// [onTapCancel] it is recommended to extend [HudButtonComponent]. void Function()? onPressed; + /// Callback for what should happen when the button is released. + /// If you want to directly interact with [onTapUp], [onTapDown] or + /// [onTapCancel] it is recommended to extend [HudButtonComponent]. + void Function()? onReleased; + HudButtonComponent({ this.button, this.buttonDown, EdgeInsets? margin, this.onPressed, + this.onReleased, Vector2? position, Vector2? size, Vector2? scale, @@ -69,6 +75,7 @@ class HudButtonComponent extends HudMarginComponent with Tappable { @mustCallSuper bool onTapUp(TapUpInfo info) { onTapCancel(); + onReleased?.call(); return true; }