Skip to main content

Game Builder Blocks - Widgets Tab

This article will dive deeper into the widgets in Game Builder. It will explain the widgets available and their properties and functions.

D
Written by David Burnham
Updated this week

Widgets are objects in the game that help us display information (such as the Text widget) or interact with the player (such as the Dialog widget). Unlike the sprites, widgets are not affected by the game’s physics. Also unlike sprites, widgets are fixed to the camera - so no matter how the camera moves, a widget will be displayed in the same place. There are different types of widgets, each with its own properties and blocks.

When a widget is added, the definition of its event’s blocks already exist in the code. If code is not added to the blocks, then nothing will happen when the event occurs.

Most other widget functions are available to use in either the widget code section or a sprite code section. You will find these functions under the Widgets menu.

Widgets available:

Widget Name

Description

Used to keep count.

Used to display text on the screen.

Used to time events in the game.

Used to show the duration of time that has passed.

Used to include buttons in the game.

Used to show a message to the player.

General Settings

All widgets have the following settings:

Settings Name

Values

Use To

Name

The default name is the widget type (i.e counter, timer, etc).

Used to reference the widget throughout the game.

Show

Checked - widget is shown (default).

Unchecked - widget is hidden.

Show or hide the widget.

Opacity

Set from 0 to 1

Controls the level of transparency, with 0 being completely transparent and 1 being completely visible.

Text Color

Color picker

Set the color of text. Note that this is not available for buttons.

Blocks

Block Name

Category

Description

Display

Shows the widget.

Display

Hides the widget.


Show

Shows the sprite or the widget.

Example

If this is written in the Timer widget, then the timer is shown.


Hide

Hides the sprite or the widget.

Example

If this is written in the Timer widget, then the timer is hidden.


Counter

The Counter widget is used to keep count. For example the score of the game or the number of lives that the player has left.

Blocks

Block Name

Description

Sets the counter to a specific value.

Changes the specified counter by a specified value.

Gets the counter value.


Set counter

The Set counter block allows you to set the counter to a specific amount. Counter set blocks can be used in either a widget or a sprite code block.

Arguments

Property Name

Values

Use To

Counter

Drop down

If multiple counters are used, this allows you to select the counter to set.

Value

0 is the default value.

The property value is displayed on the game’s screen, unless hidden.

Example

Starts the game with a counter that equals 0. This is written in the Counter widget’s code.


Change counter by

This will change the specified counter by a specific amount. The amount can be either positive or negative, but will be added to the existing value. For example, if the current value is 3 and the change by amount is 2, the counter will be updated to 5.

This block can be used in either a widget or a sprite code block.

Arguments

Property Name

Values

Use To

Counter

Drop down

If multiple counters are used, this allows you to select the counter to set.

Value

The amount tho change

Specify either a positive or negative change amount.

Example

If this code was placed in a monkey sprite, the counter would increment up by 1 each time the monkey collides with the banana.


Get counter value

This block will return the current value of the counter so that it can be used elsewhere in the program.

This block can be used in either a widget or a sprite code block.

The counter is selected in the dropdown and the numerical value is returned.

Example

If this example was placed in a monkey sprite, the game would reset if the monkey collided with the banana and the counter value was equal to 0.


Text

The Text widget is used to display labels or texts on the game’s screen.

Blocks

Block Name

Description

Sets the text to be displayed in the game.


Set text

This block sets the text to be displayed in the game.

This block can be used in either a widget or a sprite code block.

Properties

Property Name

Type

Use To

Update

Text box

Drop down

If multiple text boxes are used, this is used to select the text box to update.

Used to select the text box from the code block.

Text

string

The text to display,

"Hello world!" is the default.

Both, from the settings and code.

Examples

The string "Hello" will be displayed on the screen.

Note: the same block is used to set the text of the Text and Dialog widgets.


Timer

The Timer widget is used to time activities in the game. For example, if the game will run and end after x seconds. Or, for example, to set a time limit on a sprite’s special power.

When it gets to zero, the On End block will run.

Blocks

Block Name

Description

Starts the timer.

The On End block is called when the time of the timer ends.


Set timer

The Set timer block is used to set the value of the timer. It will always count down and this will be the starting point from where it counts down. It can be set at the start of the program or elsewhere in the program.

This block can be used in either a widget or a sprite code block.

Arguments

Name

Type

Description

Text box

Drop down

If multiple timers are used, this is used to select the timer to set.

Number Of Seconds

number

The number of seconds the timer should run for.

Example

This code will set the timer to 10 seconds at the start of the program.


On End

The On End block is called once the timer is up.

This block is defined in the widget and you will find the block in the widget code by default when the widget is created.

Example

Reset the timer to 5 when it end.

Tip

If you want to run the timer in a loop, add a Set time block in the On End block.


Clock

The Clock widget is used to show the elapsed time. It counts the elapsed seconds starting from 0 (as opposed to the timer that counts backwards until 0).

Blocks

Block Name

Description

Starts the clock.

Returns the number of seconds that have elapsed.


Start clock

Starts the clock. Once the clock is started, it cannot be stopped.

Example

This will start the clock running as soon as the game starts.


Get Seconds

Returns the number of seconds that have passed since the clock started running.

Returns

Number - number of seconds.

Example

If this is placed inside a banana sprite, the banana will be destroyed 5 seconds after the clock is started.


Button

Use the Button widget to create a simple interface for your game. For example, to start the game by clicking on a Play button.

Properties

Property Name

Type

Values

Use To

Update

Image

2 Options

Checkmark (default)

An arrow

Chose image to use for the button.

From the settings only.

rotation

number

0 - right (default)

90 - down

180 - left

270 - up

The direction in degrees that the image of the button is rotated to.

From the settings only.

Blocks

Blocks Name

Description

The On Down block is called when the button is pressed and held down

The On Click block is called when the button is released after being pressed down.


On Down

The On Down block is called when the button is pressed down. The block will be called repeatedly for as long as the button is pressed.

This block is defined in the widget and you will find the block in the widget code by default when the widget is created.

Example

In this example, for as long as the button is pressed down, the mySound sound will play.


On Click

The On Click block is called when the button is released (or clicked). This block will be called once.

This block is defined in the widget and you will find the block in the widget code by default when the widget is created.

Example

In this example, once the button is clicked (pushed down and released), the background will change to the road background.


Dialog

The Dialog widget is used to display a message to the player. The message is a string.

Properties

Property Name

Type

Use To

Update

text

string

The text to display.

Both, from the settings and code

Blocks

Block Name

Description

The set text allows the text to be updated inside the program.

The On confirm block is called when the player clicks on the button in the dialog.


Set text

The Set text block is used to update the text of the dialog box while the game is running.

This block can be used in either a widget or a sprite code block.

Arguments

Name

Type

Description

Text box

Drop down

If multiple dialog boxes are used, this is used to select the dialog box to set.

Text

String

The text that should be used to update the dialog box.

Example

When the game is run, a dialog box will open with the text Click to start game.

Note: the same block is used to set the text of the Text and Dialog widgets.


On Confirm

The On Confirm block is called when the button on the dialog is clicked on.

This block is defined in the widget and you will find the block in the widget code by default when the widget is created.

Example

Start the clock when the player clicks on a dialog.


Relevant Articles:

Did this answer your question?