- Learn
- Build a Game
- Pacific Wings
- 10 Focus
10 Focus
Hold Shift, and your Fighter slows to less than half its speed and shows its hit area, a small pale capsule at its middle. Only that capsule can be hit, as it always could. Now you can see it. Let go, and the Fighter is quick again.
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 11 from it.
To open it, start Myth Engine, choose File › Open Project... and pick the downloaded file.
10.1 The Idea
Three red tracers come down. Your Fighter is quick, and quick is the trouble now. One small nudge carries it right into the middle of them.
Hold Shift. The Fighter slows to a careful drift. A pale blue capsule shows at its middle, small beside the wings. That capsule is the hit area, the only part of your Fighter that can be hit. It always was, since Chapter 1. Now you can see it. A tracer can cross a wingtip and fly on. It only counts if it touches the capsule.
So you ease the capsule through the gap between two tracers, and they slide past on either side. Let go of Shift, and the Fighter is quick again. The capsule is gone.
That’s Focus. It’s the SLOW: HOLD SHIFT on your title screen, from Chapter 5. Until now, it was a promise on the controls panel. Now it’s true.
The capsule isn’t new to you either. You put it to work in Chapter 7, as the Milestone’s marker. That was the Hit Area Marker, and here’s the job it was saving for.
One question sits under this chapter. How does the game know you’re holding Shift? You’d think it could listen for the moment Shift goes down, and the moment it comes up. The answer is a little different, and it’s the chapter’s one hard idea.
10.2 The Plan
Here’s how the pieces work together, one chain to a line.
- Every step begins -> Focus reads its note, isFocusHeld, and sets moveSpeed: slow if the note is up, full if not. Then it takes the note down.
- Shift is held -> Focus puts the note up again, for the next step.
- The Fighter steers -> Vertical Shooter Controls reads the same moveSpeed, the one the Fighter keeps for both.
- Every step begins -> Show While Focusing hides the Hit Area. While Shift is held, it shows it again.
10.3 Set Up
One new key. Nothing new comes from the Starter Kit: the capsule’s picture has been in your project since Chapter 7.
ShiftMake the Focus Command the way you made Fire in Chapter 2: a Button, with Shift as its key. Click its No Input Assigned row, and press Shift.
10.4 Slowing Down
First the speed. Nothing on the screen changes until the last card of this chapter, because the Fighter takes everything at once. Keep going.
10.4.1 One Speed for Two
Your Fighter’s speed has lived in one place until now: moveSpeed, a Shared Variable of Vertical Shooter Controls, at 7.8. Focus needs to change that speed while you play.
So Focus gets a Shared Variable with the very same name, moveSpeed. Here’s the small surprise. On the Fighter, two Shared Variables with one name are one value, kept once, for both Logic Components. Focus writes it. Vertical Shooter Controls reads it, as it always has, and never knows the difference. A value that Logic writes while the game runs has the Kind Changeable.
10.4.2 Focus
Object Data of Logic "Focus" (its state that lasts between Events).
Sets moveSpeed, the Fighter's steering speed, at the start of every step: focusSpeedFactor of normalSpeed if the Focus Command was held in the step before, normalSpeed otherwise.
Any Objectself.focusDataself.focusData.isFocusHeld == true- Scope
Shared- Object
self- Variable
moveSpeed- Value
@self.normalSpeed * @self.focusSpeedFactor
- Scope
Shared- Object
self- Variable
moveSpeed- Value
@self.normalSpeed
- Component Value
self.focusData.isFocusHeld- Value
false
- Component Value
self.focusData.isFocusHeld- Value
true
Here’s the hard idea. You might reach for Command Pressed, to slow down when Shift goes down, and Command Released, to speed up when it comes up. That looks right, and it breaks.
Press Esc, and the game pauses, and while it’s paused, Commands don’t run their Events. So let go of Shift during the pause, and Command Released never hears it. Resume, and your Fighter is stuck slow. The same thing happens to a reserve plane. If Shift is already down when it flies up, it never sees Shift go down.
Focus doesn’t trust a moment. It looks again at every step.
Think of isFocusHeld as a note, a Yes or a No that Focus keeps for itself. At the start of every step, Focus reads the note. If it’s up, moveSpeed is slow; if it’s down, moveSpeed is full. Then Focus takes the note down. While you hold Shift, Command Held puts it back up, every step.
Count the beats of one step. It begins. Focus reads the note and takes it down. Then the Commands run, and Shift puts it back up. The next step begins, and the note is up again, so the Fighter stays slow. Let go of Shift, and the next look finds it down. Pause, unpause, a new plane: none of it matters. The next step looks again.
The step’s first moment has an Event of its own, Begin Step. It runs at the start of every step, before any Command. That’s what makes the order safe.
How slow is slow? It’s normalSpeed times focusSpeedFactor, 7.8 times 0.45, a little under half.
Make it as an Empty Logic Component, with its three Shared Variables. normalSpeed and focusSpeedFactor are Constants. moveSpeed is Changeable, starting at 7.8, the Fighter’s own speed.
The note lives in Focus’s own Data Structure. Press the + on the Data Structures card and choose New Data Structure, and Myth makes Focus Data. Its one field, isFocusHeld, is a Boolean that reads No.
Now the Events. Add Begin Step, as on Track the View in Chapter 4. Its If asks self.focusData.isFocusHeld == true. The two Change Variables go on its True line and its Else, each writing the shared speed. The card writes that as Scope Shared, Object self, Variable moveSpeed. On the block, it’s one name in the Variable box: type @self.moveSpeed.
The last step takes the note down. It comes from the Action List, and Connect to Sequence joins it after the whole If, on the main line. It has to run every step, whichever way the If went.
The second Event is Command Held, with Focus in its list, and one Change Component Value puts the note back up.
10.5 The Hit Area
Now the capsule.
10.5.1 Show While Focusing
Shows this Object only while the Focus Command is held.
Any Object- Alpha
0
- Alpha
0
Show While Focusing does the same dance with a picture instead of a speed. At the start of every step, it hides its Object, and while Shift is held, it shows it again.
Hidden, then shown, many times a second. Doesn’t it flicker? No. A step is drawn only after all its Events have run. So in a step with Shift held, the Hit Area is hidden and shown again before anyone sees it. It’s drawn shown.
The Create Event hides it once more, the moment the plane is made. Your title screen holds the world still, and no step runs behind it. So Command Held doesn’t run there either, and without that first Set Alpha 0, the capsule would sit under PACIFIC WINGS.
Make it as an Empty Logic Component with no Shared Variables, as Report Milestone was in Chapter 7, and give each Event one Set Alpha. The first two take 0. The third leaves its Alpha as it starts, and Set Alpha left that way shows the Object, as on the Reserve Plane Icons in Chapter 4.
10.5.2 Hit Area
X 0.6975, Y 1.7325411Hit Area MarkerX 0.6975, Y 1.7325The Hit Area is the Milestone’s twin. Same picture, same size, made the same way: an Empty Object, with Sprite from the toolbox’s Rendering group. Its Scene Depth is 41, one above the Fighter’s 40, so it draws on top of the plane. Attach Show While Focusing in Logic.
10.6 The Fighter
Both halves meet on the Fighter, and all of this chapter’s work comes alive at once.
X 2.88, Y 2.8840Fighter ArtX 2.88, Y 2.88CapsuleX 0, Y -0.09X 0.698, Y 1.733Center MuzzleX 0, Y 1.193Left MuzzleX -0.563, Y 1.058Right MuzzleX 0.563, Y 1.058Hit Area MarkerHit AreaX 0, Y -0.09X 2.781, Y 6.938FocusFocus DataReturn FlightReturn Flight DataChangeable7.8Expression$scrollSpeedFighter TracerClick Child Objects in the toolbox’s Core group. A Child Object is another Object the Fighter carries inside itself. It goes where the Fighter goes, and it’s removed with the Fighter. The first child is named after one of your other Objects, so pick Hit Area in its Object list, and type the card’s Name, Position and Size.
The Position puts the capsule over the Fighter’s Collider: the same capsule shape, in the same place, 0.09 meters below the middle. What you see is exactly what can be hit.
The Size looks far too big for such a small capsule. A child’s Size works like a stretch. Myth measures it against the picture’s own full size, and the Hit Area Marker is 2.781 by 6.938 meters at full size. When the two match, there’s no stretch at all. The child is drawn exactly as the Hit Area’s own card makes it. Leave the Size at 1 by 1, and the capsule is squeezed so tiny you’d hardly find it under the wings.
Then switch to Logic, and click Focus under Compatible Logic. It joins Attached Logic at the bottom, though the card lists it first. The order changes nothing here. Begin Step runs before any Command, whichever Logic holds it. Focus Data arrives with it, from the Logic.
Last, switch back to Components and look under Variables. moveSpeed now says From Logic: Vertical Shooter Controls, Focus. Set its Kind to Changeable, as the card’s line says, and leave its Value at 7.8. Now the Fighter steers at whatever speed Focus chose this step.
Save, and run the game.
Start a mission, and hold Shift. The Fighter eases down to a drift, and the pale blue capsule appears at its middle. Let go. It’s quick again, and the capsule is gone, as if it had never been there.
Watch for each of these, one at a time.
- Hold Shift on the title screen. No capsule shows there, since no step runs behind the title.
- Start a mission, and steer without Shift. The Fighter moves at its full speed, with no capsule.
- Hold Shift. The Fighter slows to a little under half its speed, and a pale blue capsule shows at its middle.
- Let go. The capsule is gone at once, and the Fighter is quick again.
- Fly so a red tracer crosses a wingtip, outside the capsule. It flies on. You keep your plane.
- Hold Shift, press Esc, and let go of Shift while PAUSED. Resume. The Fighter is quick, with no capsule.
- Press Esc, then hold Shift while PAUSED, and resume with Shift still down. The Fighter is slow, with the capsule.
- Hold Shift as you lose a plane, and keep holding it. Once the reserve plane’s controls come back, it flies slow, with the capsule showing.
A note, a speed and a capsule. Vertical Shooter Controls never knows Focus exists: it reads moveSpeed, the way it always has.
The idea underneath: don’t remember a moment, look again. A key press can slip past while the game is paused, or before a plane arrives. A look at every step can’t miss anything for long.
And when two pieces of Logic need one value, the Object carries it, as the Fighter carries one moveSpeed for both.
10.7 If It Didn’t Work
Focus is two small pieces, the speed and the capsule, so hold Shift and see which half answers.
Press Play, and a window called Can’t run yet opens? Its message names the piece and what’s wrong with it, so fix that, and press Play again.
The Fighter won’t move at all, Shift or no Shift? Look at moveSpeed under the Fighter’s Variables, whose Value should be 7.8, and at Focus’s normalSpeed beside it, which is 7.8 too. A 0 in either one stops the steering.
Shift does nothing? Open the Input Manager, and look for Focus, with Shift in its row. Then look at each Command Held block, in Focus and in Show While Focusing, where each should name Focus, not Fire.
The capsule shows, but the Fighter stays quick? Look at Focus’s two Change Variables, where each Variable box should read @self.moveSpeed. Then look at moveSpeed on the Fighter. It should say From Logic: Vertical Shooter Controls, Focus. If it shows twice, one name is spelled differently, and Focus is changing a speed nothing reads.
The Fighter slows, and stays slow after you let go? Perhaps the last step of Begin Step, the note taken down, landed inside the If’s Else. It belongs below the whole If.
The capsule never shows, or never goes? Look at the three Set Alphas in Show While Focusing. The two that hide take 0. The one under Command Held leaves its Alpha as it starts.
The capsule is far too small? Look at the child’s Size on the Fighter’s Child Objects. It should be 2.781 by 6.938.
Each of these is one 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.
Make Focus your own. Open the Fighter, and under Variables, type 0.25 into focusSpeedFactor’s Value. How does a slower Focus feel between the tracers? Or try 0.7. And Show While Focusing has no Shared Variables at all, so it works on any Object. What else in your game could appear only while Shift is down? Put things back before Chapter 11.
Still stuck? Search the manual, or ask in the Myth Engine Discord (opens a new tab).
Your Fighter can be quick or careful now, and you choose which, one step at a time. In Chapter 11, something big is waiting at the end of the route.
