Skip to content

Exit Confirmation

Jay Thakkar edited this page Aug 28, 2024 · 3 revisions

Description

The addExitConfirmation method adds an exit confirmation dialog to the specified exit button in a game. When the button is clicked, a confirmation dialog will appear, asking the user if they want to leave the game. If the user confirms, the game will exit; if they decline, the dialog will close.

Parameters

`exitBtn` (`TextButton`): The button to which the exit confirmation dialog will be attached.

Workflow

  • Pixmap Creation: I have created a Pixmap of size 1x1 with the format Pixmap.Format.RGBA8888 which is filled with a white color and then used to create a TextureRegionDrawable that serves as the background for the dialog.

  • Dialog Configuration: Created a new Dialog instance using the provided skin. The dialog's background is set to the white TextureRegionDrawable. Padding and size of the dialog are configured (40f padding, 500f width, 300f height). The dialog is set to modal, meaning it blocks input to other UI elements until it is dismissed.

  • Label and Buttons: Made a label with the text "Leave the game?", set to white color, and scaled to 1.5x. Created two TextButton instances for "Yes" and "No" responses, with their labels scaled to 1.2x.

  • Button Listeners: The "Yes" button exits the game when clicked and the "No" button hides the dialog when clicked.

  • Dialog Layout: The confirmLabel is added to the content table of the dialog and centered with padding. The yesBtn and noBtn are added to the button table with specified padding and size.

  • Dialog Positioning: The dialog is positioned center on the screen relative to the width and height.

  • Dialog Display: The dialog box opens up when the exit button on start screen is clicked.

Visual

image

Clone this wiki locally