About this manual
This manual explains how to use the action buttons (VisualScriptButton / VisualScriptTextureButton) in ACTION GAME MAKER. It also covers how to line buttons up neatly with vertical and horizontal layouts (containers), and how to put menus together — title screens, pause menus and stage selects.
What action buttons can do
Until now, building a menu with visual scripts alone meant placing one object per item, keeping “which item is selected” in a variable, and counting up and down presses with input conditions.
With action buttons, lining the buttons up is enough to move the cursor, and what happens when one is pressed is just a choice in the Inspector.
| What you want | How action buttons handle it |
|---|---|
| Choose items with keys or a gamepad | Focus moves up, down, left and right between buttons placed in a vertical or horizontal layout |
| Choose with the mouse, click to confirm | Hovering moves the focus, and a click accepts |
| Do something when an item is chosen | Pick “Execute State”, “Open Menu” or “Close Menu” |
| Change a description when the cursor moves | Set “Execute State” for “On Focus” |
| Back (cancel) | Set “Close Menu” for “On Cancel” |
| Pause menu | “Pause Game” on “Open Menu” stops the game and keeps only the menus running |
| Accept and cursor sounds | Choose a sound for each trigger |
| Show values in the button text | Placeholders such as <player.HP> work (text buttons only) |
There are two kinds of button.
| Name in the add menu | Class | Look |
|---|---|---|
| Button | VisualScriptButton | A text button (its look comes from the theme) |
| Image Button | VisualScriptTextureButton | A button drawn with images (set the normal, pressed, hover and focused images) |
Preparing a menu screen
Menus (MenuScene) are made in the map editing view.
- In the “Maps” list in the left column, press “+ New”.
- Choose “Menu” as the kind, give it a name and create it.
- Open the menu, and the CanvasLayer directly under the root appears as a layer in the Map Layers dock.
Add elements to the menu with the “+” (Add element) button on the layer’s row in the Map Layers dock. In a menu you can choose:
| Element | Used for |
|---|---|
| Label / Rich Text | Headings and descriptions. Placeholders work here too |
| Button / Image Button | Action buttons |
| Image / Color Rect / NinePatchRect / Panel | Backgrounds and frames |
| Vertical Layout / Horizontal Layout | Containers that line buttons up |
| Simple Gauge / Image Gauge | Gauges |
| Select Object… | A “manager object” for building the menu’s behaviour with a visual script |
Buttons and image buttons can also be placed on the in-game HUD (a map’s UI layer). See “Putting buttons on the HUD in a mouse-driven game” below.
Lining buttons up (vertical and horizontal layouts)
How containers work
Vertical Layout (VBoxContainer) and Horizontal Layout (HBoxContainer) are containers that arrange whatever you put in them automatically.
- A vertical layout arranges top to bottom, a horizontal layout left to right, in the order shown in the list (the Map Layers dock).
- The container decides the position and size of everything inside it. You cannot drag the buttons one by one. Trying shows the warning “Children of a container get their position and size determined only by their parent.”
- To move them, move the container itself. The buttons inside move with it and keep their order.
With keys or a gamepad, focus moves to the button next to the current one on screen: up and down in a vertical layout, left and right in a horizontal one, following the order.
Putting buttons in a vertical layout
- From the CanvasLayer’s “+”, add a “Vertical Layout”.
- Add as many "Button"s as you need the same way. For the second and later ones, right-click a button and choose “Duplicate” (Ctrl+D) to copy it with its settings.
- In the Map Layers dock, drag and drop the buttons onto the vertical layout’s row to put them inside. Select several with Shift or Ctrl clicks first to move them in one go; they go in keeping their order in the list.
- To reorder them, drag them within the list as well (several at once works too).
- Type the label of each button in its “Text”.
Adjusting position, size and spacing
Select a vertical or horizontal layout and the Inspector shows its layout properties (without opening “Advanced Settings”).
| What you want | Property to change |
|---|---|
| Put the menu in the middle of the screen | Choose “Center” or similar in “Anchors Preset” under “Layout” |
| Nudge the position | “Position” (or drag the container on the 2D screen) |
| Make the buttons the same width, or wider | Set the width with the container’s “Custom Minimum Size”, and turn on “Fill” under each button’s “Container Sizing” → “Horizontal” |
| Spacing between buttons | “Theme Overrides” → “Constants” → “Separation” |
| Align to the top, middle or bottom | “Alignment” |
| Size of one button | The button’s “Custom Minimum Size” |
Combining vertical and horizontal
Two-column menus, or confirmation screens with “Yes / No” side by side, are built by nesting containers.
CanvasLayer
└ Horizontal Layout (HBoxContainer) ← moving this moves everything
├ Vertical Layout (VBoxContainer)
│ ├ Button "Stage 1"
│ ├ Button "Stage 2"
│ └ Button "Stage 3"
└ Vertical Layout (VBoxContainer)
├ Button "Stage 4"
└ Button "Stage 5"
Built like this, the up and down keys move within a column and the left and right keys move between columns. For a background, place a Panel or NinePatchRect before the container (higher up in the list).
Setting what a button does
Select a button, and the action button settings appear at the top of the Inspector. They are split into three triggers.
| Trigger | When it happens | Actions you can choose |
|---|---|---|
| On Accept | On a click, or the accept input while focused (A by default) | None / Execute State / Open Menu / Close Menu |
| On Focus | When focus arrives by keys or gamepad, on the initial focus, or on mouse hover | None / Execute State |
| On Cancel | The cancel input while focused (B by default) | None / Execute State / Close Menu |
Each trigger also has a sound (“Audio Data ID”), for accept, cursor and cancel sounds. The cursor sound (On Focus) is not played for the initial focus when a menu opens, or when the focus returns after a menu closes.
Execute State
Starts a state of the object you specify. Most of a menu’s behaviour is built with this.
- “Target Type” decides how the target is chosen.
- Node in Scene: choose an object placed in the same menu (such as the manager object) in “Target Node”.
- Object: choose an object in the project with the “List” button of “Target Object Path”, and choose SINGLE / ALL in “Target Range”. Use this to drive objects on the map side, such as the player.
- “Target State” chooses the target’s state. The candidates are the states in the main layer of the target’s visual script.
The state is remembered by its internal ID, not its name. Adding or removing other states later does not shift the choice. If the chosen state is deleted, the Inspector shows a warning.
Open Menu
Opens the menu scene set in “Menu Scene Path” (the “List” button chooses from the list of menus). Slide and fade effects can be added, the same as the OpenMenu visual script action.
- Close Current Menu: closes the menu the button is in at the same time as the new one opens. Use it to switch menus (shown only for buttons placed in a menu).
- Pause Game: pauses the game before opening the menu (see “Pausing” below).
- Auto Resume: shown when “Pause Game” is on. On by default.
Close Menu
- “Close Menu Target” chooses Own Menu (the menu the button is in) or Last Opened Menu. A button on the HUD can only choose “Last Opened Menu”.
- Turning on “Resume Game” resumes the game after closing.
When you open menu B from menu A and close B, the focus returns to the button you pressed in A, so key and gamepad control carries on.
Focus and input settings
Focus settings
| Property | Default | What it does |
|---|---|---|
| Initial Focus | Off | Gives this button the focus when its menu opens. Turn it on for only one button per screen; key and gamepad control starts from it |
| Focus on Hover | On | Hovering the mouse moves the focus here and runs the “On Focus” action |
| Initial Focus Runs Focus Action | On | Also runs the “On Focus” action on the initial focus. Use it to show the first item’s description as soon as the menu opens |
| Wrap Focus | Off | Pressing down (right) on the last item of a vertical (horizontal) layout moves to the first, and up (left) on the first moves to the last |
If “Initial Focus” is off on every button, keys and the gamepad cannot start controlling the menu when it opens (the mouse still works). Turning it on for several buttons shows a warning in the Inspector.
Turn on “Wrap Focus” only on the buttons of the screens that need it. On a screen with a separate “Back” button below the vertical layout, pressing down would go back to the top instead of reaching “Back”.
Accept and cancel input
| Property | Default | What it does |
|---|---|---|
| Accept Input Action | Empty (use the project setting) | The input action treated as accept while focused |
| Cancel Input Action | Empty (use the project setting) | The input action treated as cancel while focused |
When empty, the project settings actg/ui/button_accept_action (default A) and actg/ui/button_cancel_action (default B) are used. With the input setup wizard’s defaults, A is the Z key and the gamepad A button, and B is the X key and the gamepad B button.
The Enter and Space keys do not accept. They are also used for things like jumping during the game, and this keeps buttons from being accepted by accident. To accept with Enter / Space too, choose ui_accept as “Accept Input Action”. If the chosen input action has been removed from the project, a warning is shown and Enter / Space and Escape are used instead.
Building the menu’s behaviour with a visual script (the manager object)
The basic pattern is for a button’s “Execute State” to call a state of an object placed inside the menu.
- Create one object, such as an Area2DGameObject, and give it a visual script that manages the menu (the “manager object” below).
- From the menu CanvasLayer’s “+”, place the manager object with “Select Object…”.
- In the manager object’s visual script, make the states the buttons will call (“show the description of stage 1”, “go to stage 1”, and so on).
- On each button, set “Target Type” to “Node in Scene”, choose the manager object as “Target Node”, and that state as “Target State”.
To switch descriptions or images, the easiest way is to use ChangeObjectProperty in the manager object’s states to change a label’s text or show and hide images.
Examples
A pause menu
- Make a menu for pausing and put buttons such as “Resume” and “To Title” in a vertical layout.
- Set the “Resume” button as follows.
- On Accept: action “Close Menu”, Close Menu Target “Own Menu”, and “Resume Game” on
- “Initial Focus” on
- Give every button the same “On Cancel” as “Resume” — “Close Menu” plus “Resume Game” — so that B goes back from anywhere (select several buttons to set them together).
- Open the pause menu from the game side.
- From the player’s visual script: put OpenMenu in the state entered by the pause input, and turn on “Pause Game”.
- From a HUD button: set its On Accept action to “Open Menu” and turn on “Pause Game”.
A stage select
- Line up one button per stage (the layout from “Combining vertical and horizontal” works well).
- Place a description label, preview images and a manager object.
- Set each button as follows.
- On Focus: “Execute State” with the manager object’s “show the description of stage N” state
- On Accept: “Execute State” with the manager object’s “go to stage N” state (that state changes the scene)
- Turn on “Initial Focus” on the first button only. With “Initial Focus Runs Focus Action” on, the first description appears as soon as the menu opens.
From one menu to another
- Opening on top (open an options screen and return when it closes): just set On Accept to “Open Menu”. Set the opened menu’s “Back” button to “Close Menu” (Own Menu), and when it closes the focus returns to the button in the original menu.
- Switching (title → stage select, where the original screen is no longer needed): turn on “Close Current Menu” on “Open Menu”. The new menu opens first, then the original one closes.
- Menus opened on top during a pause also keep running, and switching menus keeps the pause.
Putting buttons on the HUD in a mouse-driven game
Buttons and image buttons can be added from the “+” of a map’s UI layer. Buttons on the HUD are placed without focus, so in-game keys (such as Space) never accept them (Focus → “Mode” is “None”). They react to mouse clicks only.
If an object acts on a mouse input condition, such as “attack on click”, the click that presses the button would also attack. Turning on “Skip When Button Hovered” on the MouseInput condition makes it not met while the cursor is over a button.
Pausing
Turning on “Pause Game” on “Open Menu” (on a button or on the visual script action) pauses the game before the menu opens.
| What | While paused |
|---|---|
| Objects, physics, camera and effects in the game scene | Stop |
| Buttons on the map’s UI layer (HUD) | Stop |
| Open menus, and menus opened during the pause (their buttons and manager objects) | Keep running |
| Menu open and close effects | Keep running |
| BGM and sound effects | Keep playing |
The pause is released in one of three ways:
- “Resume Game” on a button (On Accept or On Cancel)
- “Resume Game” on the CloseMenu visual script action
- Automatically when no menu is shown any more (when “Auto Resume” is on)
HUD buttons stop too, so the HUD alone cannot toggle “pause / resume”. Put the button that resumes the game in the menu that opens.
To choose what stops yourself (for example, keep background animations moving and stop only the characters), you can skip pausing and instead turn a switch ON in the state that opens the menu, adding “the switch is OFF” to the transition conditions of the objects you want to stop.
Notes
- Not being able to move buttons one by one is how containers work. Move the container to change their position.
- Turn on “Initial Focus” for only one button per screen. With none on, keys and the gamepad cannot start controlling the menu.
- By default accept and cancel are A / B (the Z / X keys), not Enter / Space / Escape. Change “Accept Input Action” and “Cancel Input Action”, or the project settings, to use others.
- If other objects watch the same input as the button’s accept with InputCondition, both react. Pause while the menu is open, or stop the other objects with a switch.
- Buttons do not react while a menu’s open or close effect is playing.
- With Target Type “Object” and range “SINGLE”, only one of several identical objects moves. To move a specific one, specify it with “Node in Scene”.
- Text and image displays let clicks through, so buttons behind them can still be pressed. To prevent that, hide the buttons or make them “Disabled” (ChangeObjectProperty can switch it).
- Godot’s standard Button / TextureButton already placed do not become action buttons. To give them actions, place new “Button” / “Image Button” elements from the menu’s “+”.