(Spicifying it a Super Bowl taco style)
(updating cat)
 
(19 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Merge|Indirect Start}}
+
A [[Menu (project)#Types of Menus|'''Main Menu''']] is a menu, usually used in games, placed at the beginning of a [[project]]. It allows the [[Scratcher|user]] to decide to play the [[Game Projects|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.
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==
+
== Basic Menu ==
[[Broadcast|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 Flasg|green flag]] to navigate back to the menu. The broadcast used in this tutorial is named <code>openMenu</code>
+
[[Broadcast]]ing 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|green flag]] to navigate back to the menu. The broadcast used in this tutorial is named <code>openMenu</code>
 
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,
 
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:
 
For example, one's original script might look like this:
 
<scratchblocks> when gf clicked
 
<scratchblocks> when gf clicked
 
forever
 
forever
if <key [left arrow v] pressed?>
+
if <key [left arrow v] pressed?> then
point in direction (-90)
+
change x by (-10)
move (10) steps
 
 
end
 
end
if <key [right arrow v] pressed?>
+
if <key [right arrow v] pressed?> then
point in direction (90)
+
change x by (10)
move (10) steps
 
 
end
 
end
if <key [space v] pressed?>
+
if <key [space v] pressed?> then
 
broadcast [jump v]
 
broadcast [jump v]
 
end </scratchblocks>
 
end </scratchblocks>
Line 23: Line 20:
 
when I receive [start game v]
 
when I receive [start game v]
 
forever
 
forever
if <key [left arrow v] pressed?>
+
if <key [left arrow v] pressed?> then
point in direction (-90)
+
change x by (-10)
move (10) steps
 
 
end
 
end
if <key [right arrow v] pressed?>
+
if <key [right arrow v] pressed?> then
point in direction (90)
+
change x by (10)
move (10) steps
 
 
end
 
end
if <key [space v] pressed?>
+
if <key [space v] pressed?> then
 
broadcast [jump v]
 
broadcast [jump v]
 
end </scratchblocks>
 
end </scratchblocks>
  
 
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:
 
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:
<scratchblocks> when gf clicked
+
<scratchblocks>
show  
+
when I receive [openMenu v]
switch backdrop to [Title Backdrop v]</scratchblocks>
+
show
and another starts the game when it's clicked.
+
switch backdrop to [Title Backdrop v]
<scratchblocks> When this sprite clicked
+
</scratchblocks>
 +
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:
 +
<scratchblocks>
 +
When this sprite clicked
 
broadcast [start_game v]
 
broadcast [start_game v]
 
switch backdrop to [Gameplay Backdrop v]
 
switch backdrop to [Gameplay Backdrop v]
hide </scratchblocks>
+
hide
 +
</scratchblocks>
 +
Now when someone starts the project, it will show the menu instead of starting the game automatically.
  
Now, when someone starts the project, it will show the menu instead of starting the game automatically.
+
== Adding Title Music ==
 
 
 
 
==Adding Title Music==
 
  
 
You can also add title music to your game.
 
You can also add title music to your game.
Line 86: Line 83:
 
hide </scratchblocks>
 
hide </scratchblocks>
  
This cuts off the supply of title music, and the just stops it altogether.
+
This prevents the title music from playing again, and then just stops it altogether.
 
 
  
==External Links==
+
== External Links ==
  
*[http://scratch.mit.edu/projects/243051/ Project]
+
* [http://scratch.mit.edu/projects/243051/ Project]
  
 
[[Category:Scripting Tutorials]]
 
[[Category:Scripting Tutorials]]
[[Category:How To Pages]]
+
[[Category:Game Design Tutorials]]

Latest revision as of 21:20, 8 January 2019

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 prevents the title music from playing again, and then just stops it altogether.

External Links