- Learn
- Build a Game
- Pacific Wings
- 5 Title, Pause and Play Again
5 Title, Pause and Play Again
Your game starts the moment you press Play, and a failed mission stays failed. This chapter gives it a front door. PACIFIC WINGS opens over the sea, with the controls and a START MISSION button. Press Enter, and the mission begins, with the score and your reserve planes at the top left. Esc pauses the world under a dark veil. When a mission fails, PLAY AGAIN takes you back to the title, where your best score waits.
The game as it is at the end of this chapter. Click the game, then press Enter to start.
If your game and this chapter part ways, here is the chapter’s finished project. Open it and compare, or start Chapter 6 from it.
To open it, start Myth Engine, choose File › Open Project... and pick the downloaded file.
5.1 The Idea
The sea fills the screen, and the carrier sits on it, long and gray. Across the top, in big cream letters, it says PACIFIC WINGS. Below that, a dark panel tells you the keys, and a button says START MISSION. Nothing moves. The world waits for you.
Right now your game has no such moment. Press Play, and you’re flying before you’ve found the keys. Lose the last plane, and MISSION FAILED hangs there for good, with a PLAY AGAIN button that does nothing. Stopping the game is the only way out.
This chapter gives the mission a beginning and a way back to it.
The title, the pause and PLAY AGAIN are all menus. A menu is a group of Screen UI Objects that show and hide together, and the keys can work it. Arrow keys move between its buttons. Enter chooses one. A menu can also hold the world still while it’s open. That’s how the title screen waits, and how Esc pauses.
The pieces of a menu share a UI Group, the Group you typed into UI Interaction in Chapter 4. Show the group, and every piece in it shows.
The Game State comes back too. In Chapter 4, a mission was Playing, and then perhaps Mission Failed. Now it starts on a third state, Title. Several pieces of Logic listen for each change of state, and each does its own small job. When the state becomes Playing, the score and the cream planes appear. When it becomes Mission Failed, they go.
Last, the best score. A Global like $score lives only while the game runs. Close the game, and it’s gone. The best score has to outlast that, so the game writes it down on this computer as a Persistent Value. It works like a note the game leaves for itself, and reads the next time it starts.
5.2 The Plan
Here’s how the pieces work together, one chain of events to a line. Glance at it now, and come back as you build.
- The game starts -> Mission Start shows the Start Menu and holds the world still -> Best Score reads the saved best, and shows BEST if there is one.
- Enter, or a click on START MISSION -> the Start Menu sends startMission -> Mission Start sets the Game State to Playing and hides the menu; Best Score hides BEST.
- The Game State changes to Playing -> Show the Flight HUD shows the score and the reserve planes.
- Esc while Playing -> Pause shows the Pause Menu and holds the world still.
- RESUME, Enter or Esc -> the Pause Menu sends resumeMission -> Pause lets the world go and hides the menu.
- The Game State changes to Mission Failed -> Show the Flight HUD hides the score and the planes -> Best Score keeps the higher score on this computer.
- PLAY AGAIN, or Enter -> the Mission Failed Menu sends playAgain -> Play Again restarts the game, at the title.
5.3 Set Up
Three pictures from the Starter Kit join the game: the Controls Panel, the Menu Button Panel and the Pause Dimmer. They’re in your project already.
EnterEscapeTitle, Playing, Mission FailedTitleCOMMANDS has two new Button Commands. Make them the way you made Fire in Chapter 2, in Game Settings > Input Manager. Start Mission takes the Enter key: click its No Input Assigned row, and press Enter.
Menu Cancel takes Escape, and Escape needs one small trick. While Myth listens for a key, a single Escape means “never mind”, and it stops listening. The line under the row says Press Escape again to use Escape; otherwise this cancels. So press Escape twice, quickly, and the row reads Escape.
GLOBAL VARIABLES adds $bestScore. Make it the way you made $planes, from the Globals card of any Logic Component, with New Global…. Its name is bestScore, with no $, and its Default stays 0.
GAME SETTINGS > General > Game State has two lines this time. Make the Title state first. Press Add Game State, the + under Available Game States. Type Title as its Game State Name, and press the window’s own Add Game State button, as you did for Mission Failed. Your list now reads Playing, Mission Failed, Title. The card shows Title at the top, but where a state sits in that list changes nothing. Only its name counts.
Then pick Title in the Initial Game State list above it. That’s the state the game starts in. The word Initial, which sat beside Playing, moves to Title.
PLACE THESE waits for its Objects, and so does CHANGE THESE PLACEMENTS. Each comes in its own part.
5.4 The Title Screen
The front door comes first: the title, the keys, and the button that starts it all.
Three Screen UI Objects make the title screen. They share the Group title, so they show and hide together. All three sit around the middle of the screen, with Screen Anchor Center, as the Mission Failed screen did.
Window / UICenterUIX 32, Y 32PACIFIC WINGS60Bold#FFF4CFCenterWrap to Width560TexttitlemenuChoiceWindow / UICenterUIX 32, Y 32-1Controls PanelX 269.5, Y 38.4MOVE: ARROWS / WASD FIRE: HOLD SPACE [new line] SLOW: HOLD SHIFT PAUSE: ESC11Regular#B7E8EFCenterTexttitlemenuChoiceWindow / UICenterUIX 268, Y 60-1Menu Button PanelX 268, Y 60START MISSION20Bold#8EEFFFCentertitlestartMissionMoveStart MissionYou’ve made Objects like these in Chapter 4, so your hands know the way. Make each a Screen UI Object. Go down its card from the top. Set Text / UI in the Properties on the left, and pick Wrap to Width before you type a Text Frame width.
The Controls Text keeps its words in two lines. Type the first line into the Text box, press Enter, and type the second. There are five spaces between WASD and FIRE, and five between SHIFT and PAUSE, as on the card. Its Emphasis is Regular, which is where it starts, so there’s nothing to change there.
Start Menu is the button, so its Element Type stays Button. The Event, startMission, is the message it sends when it’s chosen. Two lists follow. Its Navigation Command is Move, the arrow keys and WASD, which step from button to button. Its Confirm Command is Start Mission: Enter chooses. Your two new Commands are in both of them, at the end.
5.4.1 Mission Start
When the game begins, Mission Start opens the Start Menu and holds the world still behind it. Then it waits. When startMission arrives, it sets the Game State to Playing and closes the menu. The world goes on.
Shows the title screen when the game begins, and starts the mission when START MISSION is chosen.
Any Object- Menu Element
Start Menu
- Menu Element
Start Menu
- Game State
Playing
- Operation
Hide- Menu Element
Start Menu
Control Menu opens a menu, and every Object in the menu’s Group comes with it. That’s why the card names only “Start Menu”. The title and the keys share its Group, so they appear too. Set Menu Pause State holds the world still while that menu is open.
Make it as an Empty Logic Component. Under Game Start, Control Menu and Set Menu Pause State each have a Menu Element slot. Pick Start Menu in both.
The startMission message isn’t sent by any Logic. A button sends it, so it isn’t in the Add Event list yet. Choose Add Custom Event… there, as you did for noMoreHealth in Chapter 3, and type startMission. Under it, Set Game State picks Playing. The second Control Menu has an Operation list, which starts on Show. Pick Hide, and type "Start Menu" into its box.
FighterWhy does hiding the menu let the world go? The hold belongs to the open menu, not to the world. Close the menu, and the hold goes with it, so Mission Start needs nothing more.
Attach Mission Start to Game Rules. The other three new lines on this card come later in the chapter.
Now place the title screen, from PLACE THESE. Title Text, Controls Text and Start Menu each go on the screen, hidden, with Z-Index 10002, the way you placed the Mission Failed screen. They’re hidden because the menu shows them.
Run the game. PACIFIC WINGS sits over a still sea, with the keys and START MISSION below. Nothing moves. Press Enter, and the title is gone and the mission begins.
5.5 The Flight’s Display
The score has been counting out of sight since Chapter 3. Now it shows while you fly.
Score Text and the five cream planes become one group, flight. A new piece of Logic shows that group when the mission starts, and hides it when the mission ends.
Window / UIUIX 32, Y 32SCORE {$score}15Bold#FFF4CFWrap to Width240TextflightmenuChoiceWindow / UIUIX 32, Y 32Reserve Plane Icon ArtX 22, Y 22TextflightmenuChoiceBoth cards add UI Interaction back. You removed it when you made them. Open each Object, and click UI Interaction in the toolbox’s Core group. Its Element Type is Text, its Group flight, and its Event menuChoice. A text has no Event to send, but the game keeps the name, so the cards do too.
5.5.1 Show the Flight HUD
Show the Flight HUD asks one question each time the Game State changes: is the mission being played now? Yes, and the flight group shows. Any other answer, and the whole group hides at once.
Shows the flight HUD (SCORE and the reserve plane icons) while the mission is being played, and hides it when the mission ends.
Any Objectevent.current == "playing"- UI Group
"flight"
- UI Group
"flight"- Visible
No
Make it as an Empty Logic Component. Its one Event is Game State Changed, which runs whenever the state changes. The If asks event.current == "playing", the state’s own name in lower case. A name of two words gets a hyphen. Mission Failed is "mission-failed". Set UI Group Visibility shows or hides every Object in one Group. Type "flight" into its UI Group box. This is text, so keep the quote marks the card shows. Its Visible starts on Yes. The Otherwise comes from Add Else, with a second Set UI Group Visibility for "flight", and there Visible goes to No.
It’s on Score Text’s card, so attach it there. Any Object could carry it. Score Text is the heart of the flight’s display, so it lives with the score.
Showing the group shows all five icons. So why only two cream planes? Because the two pieces of Logic each work on something different, and they never touch each other’s. Show the Flight HUD shows or hides. Show While in Reserve, from Chapter 4, sets each icon’s Alpha, and an icon with no plane behind it has Alpha 0, fully see-through. Shown, but clear as glass.
Now CHANGE THESE PLACEMENTS. Select each of the five Reserve Plane Icons in Route’s Scene Explorer, and turn off its Visible at Game Start. While the title shows, the cream planes stay out of sight.
Run the game. The title shows, and nothing at the top left. Press Enter, and SCORE 0 appears with two cream planes under it. Lose all three planes, and the score and the planes vanish at once. Three seconds later, MISSION FAILED takes their place.
5.6 Pause
Now Esc can stop the whole sky at once, under a dark veil.
The pause screen is three more Objects in one Group, pause. A see-through dark sheet covers the whole screen, PAUSED sits over it, and a RESUME button waits below.
Window / UICenterUIX 32, Y 32Pause DimmerX 1400, Y 1000TextpausemenuChoiceWindow / UICenterUIX 32, Y 32PAUSED34Bold#FFF4CFCenterWrap to Width560TextpausemenuChoiceWindow / UICenterUIX 268, Y 60-1Menu Button PanelX 268, Y 60RESUME20Bold#8EEFFFCenterpauseresumeMissionMoveStart MissionMenu CancelresumeMissionThe Pause Dimmer is a picture, 1400 by 1000 pixels, big enough to cover the whole game. It has no Text / UI. Its card gives no Z Index Within Object either.
The Pause Menu is the button, and it has two lines the Start Menu didn’t. Its Cancel Command is Menu Cancel, the Esc key, and its Cancel Event is resumeMission, the same message as its Event. So RESUME answers three ways: a click, Enter, or Esc. All three send resumeMission.
5.6.1 Pause
Pause listens for Esc. When Esc is pressed, it first asks whether a mission is being played. On the title screen, or after a mission has failed, the answer is no, and nothing happens. While Playing, it opens the Pause Menu and holds the world still. Later, resumeMission arrives. Pause lets the world go and closes the menu.
Esc pauses the world while a mission is being played; RESUME (or Esc, or Enter) carries on.
Any Object- Action Name
isPlaying- Game State
Playing
isPlaying.value == true- Menu Element
Pause Menu
- Menu Element
Pause Menu
- Menu Element
Pause Menu- Pause the World
No
- Operation
Hide- Menu Element
Pause Menu
Make it as an Empty Logic Component. Its first Event is Command Pressed, which runs once for each press of a key. Its second window, Command Pressed — choose Command, lists your Button Commands. Pick Menu Cancel.
The first half works like Planes’ fighterLost Event in Chapter 4. Check Game State names its answer isPlaying, and the If asks isPlaying.value == true. On its True line, Control Menu and Set Menu Pause State both pick Pause Menu in their Menu Element slots. Each comes from the If’s own menu: right-click the If, choose Add Inside Then, and join it with Connect to Sequence.
Add the resumeMission message with Add Custom Event…, the way you added startMission for Mission Start. Under it, Set Menu Pause State has a second box, Pause the World, which starts on Yes. Pick No, and the world is free to go on. Then Control Menu, on Hide, closes the menu. Closing it would free the world anyway, as it does on the title screen, but Pause says so plainly first.
Attach Pause to Game Rules. Then place the three from PLACE THESE, on the screen and hidden. The Pause Dimmer’s Z-Index is 10001, one less than the others, so it lies under PAUSED and RESUME.
Run the game and press Enter. Then press Esc. The sky goes dark and still, with PAUSED and RESUME over it. Press Esc again, and the world picks up where it stopped.
Esc does two jobs now, so you might wonder whether that second press pauses again. It doesn’t. While the world is held still, its Logic waits too, and Pause never hears it. Only the open menu does, and its Cancel Command sends resumeMission.
5.7 Play Again
PLAY AGAIN has waited since Chapter 4.
Window / UICenterUIX 268, Y 60-1Mission Failed PanelX 268, Y 60PLAY AGAIN20Bold#FFCA75CentermissionFailedplayAgainMoveStart MissionOpen Mission Failed Menu, and select its UI Interaction in Attached Components. Type playAgain into its Event box, over anything the box shows. Its two Commands come from the card’s lists. Now Enter chooses PLAY AGAIN, the way it chooses START MISSION on the title.
5.7.1 Play Again
Restarts the whole game when PLAY AGAIN is chosen.
Any ObjectOne Event, one Action. When playAgain arrives, Restart Game starts the whole game over from its first Scene. Every Game Start runs again: the title shows, $planes goes back to 3, and $score to 0.
Make it as an Empty Logic Component. playAgain comes from Add Custom Event…, and Restart Game has nothing to set. Attach it to Game Rules.
Run the game, and lose all three planes. When MISSION FAILED shows, press Enter on PLAY AGAIN, the screen’s only button. The title comes back, and the mission waits for you again.
5.8 The Best Score
The last piece remembers your best mission.
Window / UICenterUIX 32, Y 32BEST {$bestScore}16Bold#FFCA75CenterWrap to Width300TextbestmenuChoiceBest Score Text sits under START MISSION, and you make it like Title Text. Its Text has two spaces after BEST, as on its card, and its Group is best, a group of its own. It isn’t part of the title’s menu, because a first-time player has no best score to show.
5.8.1 Best Score
Best Score has three jobs, one for each Event.
When the game starts, it reads the saved best. Load Persistent Value looks up a value by its Key, a name you choose, here “bestScore”. When nothing has been saved yet, it hands back its Default, 0. Its answer is named savedBest, and Change Variable copies savedBest.value into $bestScore. If $bestScore is more than 0, BEST shows.
When startMission arrives, BEST hides, because the title is going away.
When the Game State changes to Mission Failed, the score is final. If it beats $bestScore, $bestScore takes it, and Save Persistent Value writes it down under the same Key. Next time the game starts, Load Persistent Value finds it there.
Keeps the best score on this device: shows it on the title screen and raises it when a mission ends.
Any Object- Action Name
savedBest- Key
"bestScore"- Default
0
- Variable
$bestScore- Value
savedBest.value
$bestScore > 0- UI Group
"best"
- UI Group
"best"- Visible
No
event.current == "mission-failed"$score > $bestScore- Variable
$bestScore- Value
$score
- Action Name
bestSaved- Key
"bestScore"- Value
$bestScore
Make it as an Empty Logic Component. Under Game Start, Load Persistent Value has three boxes, and its Action Name starts with a long name of its own. Type savedBest over it. Then "bestScore" goes into its Key, quote marks and all, and 0 into its Default. The If asks $bestScore > 0, and Set UI Group Visibility takes "best", with its quote marks.
The startMission message is in the Add Event list now. Mission Start uses it. Under it, a second Set UI Group Visibility takes "best", with Visible on No.
The third Event, Game State Changed, has an If inside an If, the same question Mission Failed Screen asks on the outside, and the new record on the inside. The inner If comes from the outer If’s Add Inside Then. Save Persistent Value starts with a Value of 0, so its card’s line goes in over it.
Attach Best Score to Game Rules. On the Game Rules card it’s the third new line, before Play Again. The order you attach them in doesn’t matter. Place Best Score Text from PLACE THESE, on the screen and hidden, like the others.
Run the game. The first time, the title shows no BEST: nothing has been saved. Shoot down an enemy or two, lose all three planes, and press Enter on PLAY AGAIN. Now BEST sits under START MISSION, with your score beside it. Stop the game, run it again, and it’s still there.
Your game has a front door, a pause, and a way back to the start.
Watch for each of these, one at a time.
- The game opens on PACIFIC WINGS, the keys panel and START MISSION, over a sea that doesn’t move.
- Esc on the title does nothing.
- Enter starts the mission. The title goes, and SCORE 0 appears at the top left, with two cream planes under it.
- Esc while flying darkens the screen and stops everything: the camera, the enemies, the tracers. PAUSED and RESUME sit in the middle.
- Esc again, or Enter, and everything moves on from where it stopped.
- Lose your last plane. The score and the cream planes vanish at once, and MISSION FAILED shows three seconds later.
- Enter on PLAY AGAIN brings back the title. If your score was more than 0, BEST shows it under START MISSION.
- Stop the game and run it again, and BEST is still there.
A title that waits. A score that shows only while you fly. A pause, a way back, and a best score that outlasts the game.
Three things carried it. Menus are groups of Screen UI Objects that show together, and the world can hold still behind them. The Game State is one switch for the whole mission, and each piece of Logic that cares listens for its changes, so no piece has to tell the others. And a Persistent Value is the one thing in this chapter that survives the game closing. Everything else starts fresh with each Game Start.
5.9 If It Didn’t Work
Menus have many small boxes, and a slip in one is part of the work. Run the game, and watch what happens.
Press Play, and a window called Can’t run yet opens instead? Its message names the piece with the slip, and what’s wrong with it. Fix it, and press Play again.
The title never shows, and you’re flying at once? Look at Mission Start’s Game Start, where both blocks should pick Start Menu in their Menu Element slots. Then look at Initial Game State, in Game Settings > General: it should be Title.
The title shows, but Enter does nothing? Open Start Menu, and select UI Interaction. Its Confirm Command should read Start Mission, and its Event startMission. In Game Settings > Input Manager, Start Mission should have Enter.
The score never shows? Look at Show the Flight HUD’s If. Its condition should end with "playing", in lower case, between quote marks. Its two UI Group boxes should read "flight", with the quote marks.
Esc does nothing while you fly? Look at Menu Cancel, in Game Settings > Input Manager. If its row still reads No Input Assigned, the first Escape cancelled the capture. Click the row, and press Escape twice, quickly.
The world stays still after RESUME? Look at the second Set Menu Pause State in Pause. Its Pause the World should read No.
BEST never shows? A score of 0 is never saved, so shoot down at least one enemy first. Last, look at Best Score’s two Keys: both should be "bestScore", spelled the same.
Each of these is one small fix. Make it, run the game again, and you’re back with the chapter. The catch-up download in the Goal is this chapter’s game, finished, if you’d like to compare.
The front door is yours to decorate. Give Title Text a second line under PACIFIC WINGS, a few words of your own, in a smaller size. Or try another Color for START MISSION. Then put things back the way the cards have them before Chapter 6.
Still stuck? Search the manual, or ask in the Myth Engine Discord (opens a new tab).
Your mission has a beginning, a pause and an end. In Chapter 6, it gets harder: two more kinds of enemy wait along the route.
