Revision as of 21:24, 26 July 2017 by BotanAI (talk | contribs) (Basic Menu: Rotated the sprite unnecessarily. Steps should only be used when sprites will likely rotate during movement.)

A main menu is a menu, usually used in games, placed at the beginning of a project. It allows the user to decide to play the game, or use other features within the project, such as character customization. Main menus mostly consist of various buttons for accessing the different parts of a project. For this tutorial, it is assumed that the majority of the project's body is complete.

Basic Menu

Broadcasting is useful for main menus because it allows them to be easily pulled up multiple times in a project. It avoids the need to click the green flag to navigate back to the menu. The broadcast used in this tutorial is named openMenu In order to start, you will need to replace most "When Green Flag Clicked" script with "When I receive [openMenu]" scripts, likely with exceptions. It's recommended to plan for this in advance, and not use "When Green Flag Clicked" hats for the main menu, For example, one's original script might look like this:

 when gf clicked
forever
if <key [left arrow v] pressed?> then
change x by (-10)
end
if <key [right arrow v] pressed?> then
change x by (10)
end
if <key [space v] pressed?> then
broadcast [jump v]
end 

But after the modification, it would look like this:

when I receive [start game v]
forever
if <key [left arrow v] pressed?> then
change x by (-10)
end
if <key [right arrow v] pressed?> then
change x by (10)
end
if <key [space v] pressed?> then
broadcast [jump v]
end 

After this, make a separate backdrop for your title screen that includes your title and a new sprite named "Start Button". Inside this sprite, make two scripts:

 
when I receive [openMenu v]
show 
switch backdrop to [Title Backdrop v]

The "Play" button is used for triggering the project to begin. Most often, when the button is clicked a message will be sent signaling the game to begin. The following script represents this:

 
When this sprite clicked
broadcast [start_game v]
switch backdrop to [Gameplay Backdrop v]
hide

Now when someone starts the project, it will show the menu instead of starting the game automatically.

Adding Title Music

You can also add title music to your game.

Variables you will need:

 (Main Menu?) 

In any sprite, create a script like this one:

Note Note: Do this after you've created your menu. Do not convert this into a "start_game" script.
when gf clicked
set [Main Menu? v] to (1)
forever
if <(Main Menu?)>[0]> then
play sound [Title Music v] until done
end 

This script says that if you are on the main menu, it will play the music.

Now, you will need to modify your Start Button script: Change it from this:

when this sprite clicked
broadcast [start_game v]
switch backdrop to [Gameplay Backdrop v]
hide 

to this:

when this sprite clicked
broadcast [start_game v]
set [Main Menu? v] to (0)
stop all sounds
switch backdrop to [Gameplay Backdrop v]
hide 

This cuts off the supply of title music, and then just stops it altogether.

External Links