11 Sky
In Chapter 1, the screen was dark, with no stars yet. By the end of this chapter, deep space hangs behind your Ship: a nebula, far stars, gas, middle stars, near stars and dust, each drifting at its own speed. Fly, and the near dust streams past while the nebula hardly moves. Clear a field, and the whole sky surges forward into the next sector. This is the last chapter. At the end of it, Shatterfield is complete.
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, ready to open and compare with yours.
To open it, right-click the downloaded file, choose Extract All... and then Extract. Start Myth Engine, choose File › Open Project... and pick the .mythproj file in the new folder. Beside it, OFL.txt is the license of the project’s font, Press Start 2P.
11.1 The Idea
Press Enter, and the title fades. Behind it the sky is already moving. Far back hangs a nebula in teal, violet and gold, and in front of it, layer on layer, come stars and threads of gas and fine dust. Every layer creeps to the left, and the nearer ones creep faster.
Now hold Up and fly. The dust streams past, the near stars slide, and the nebula barely shifts. You can feel how deep it is.
You’ve seen this from the side window of a moving car. The fence posts rush by, while the hills behind them drift and the moon seems to ride along with you. Nothing out there is moving. Only you are, and the nearer a thing is, the faster it seems to go.
That’s the whole trick of this sky. Each of the six layers slides against the Ship’s motion by its own share, its depth. The nebula’s depth is tiny, and the dust’s is nearly half.
Now break the last rock of a wave. Sector Clear plays, and every layer rushes forward at once, the far ones and the near ones together, as the Ship jumps to the next sector. Then the sky eases back to its drift. Remember Chapter 10’s promise? Waves sends waveCleared to the whole game, and from this chapter on, the sky listens for it too.
Six layers could mean six copies of the same Logic, one for each. This chapter makes one. A Data Table holds the layers, one row each, and one Logic Component, Sky Parallax, reads the rows in a loop.
11.2 The Plan
Here’s the chapter as a chain, read from left to right.
- Every step -> Sky Parallax reads the Ship’s velocity, or 0 when there’s no Ship -> its own sky velocity closes part of the gap between the two.
- At the end of every step -> Sky Parallax runs through Sky Layers, row by row -> each Background gets its sliding speed: its drift, minus the Ship’s share, minus the surge.
- The last rock is gone -> Waves tells the whole game waveCleared -> the surge eases in.
- The next wave begins, or the game ends -> nextWave or playStopped -> the surge eases out.
11.3 Set Up
The Set up card starts with six BACKGROUND blocks, one for each layer, from Nebula Panorama at the back to Space Dust at the front. Each has one layer, an Image. All six came with the Starter Kit, pictures and all, so there’s nothing to make here. You’ll find them in the Resources, under Backgrounds.
The last block is new work. The Scene called Space shows the six Backgrounds, in this order.
Open Space, pick Select above the preview, and click an empty spot, as you did for its Background Color in Chapter 1. The Properties show the Scene. Below Composition is Screen Backgrounds, with a list that reads Add Background….
Pick Nebula Panorama in that list. It joins the Scene, and the Properties now show that one Background. Click an empty spot again. The sky in the preview doesn’t count, so any spot with no Object will do. The list is back, so add Stars Far next, and so on down the card.
The order is the depth. The first one in the list is the farthest back, and each one after it is drawn in front. If two land the wrong way round, drag one by the grip at the left of its row.
Run the game now, and the sky is there. It hangs still, though. Nothing slides it yet.
11.4 Six Layers
Each layer needs a few numbers of its own. A table keeps them side by side.
11.4.1 Sky Layers
Sky Layers is a Data Table with one row for each layer, back to front. Its first column picks the row’s Background. The other four are numbers.
The first two, driftX and driftY, are the layer’s own drift, in pixels of its picture each second. The nebula creeps at -4, and the dust at -42, ten times as fast. The third, depth, is the share of the Ship’s motion the layer slides against, from 0.015 for the nebula to 0.45 for the dust. The last, surge, is how fast the layer rushes in a sector jump, from 700 at the back to 3200 at the front.
Read down any column, from far to near. The numbers grow in size, or now and then stay level. The signs only say which way a layer drifts: a minus in driftX goes left, and a plus in driftY goes up.
Make it with Add > Data Table, as you made Asteroid Materials in Chapter 6. Myth makes Sky Layers Entry along with it. It’s under Data in the Resources. Open it, and press Add Field once for each line of its card.
One row of the "Sky Layers" Data Table.
The first field is background. Pick Background in its Type list, among the kinds of thing below the plain values, and its Value turns into a list that reads None. The other four stay Numbers at 0, so only their names change: driftX, driftY, depth and surge.
Back in the table, the five columns are there. The background column’s small tag reads Object, as the sprite column’s did in Chapter 6.
Nebula Panorama-400.015700Stars Far-710.04700Gas Filaments-101.50.07950Stars Mid-1420.11300Stars Near-2430.22000Space Dust-4250.453200Add Row six times. Double-click each name in the Entry column, type the card’s, and press Enter. Each background cell is a list. Pick the row’s own Background there. Double-click a number cell, type the card’s number, and press Enter. A minus sign goes in first, as in -4.
11.5 The Sky Moves
Now the table needs a reader.
11.5.1 Sky Parallax
Sky Parallax lives on Game Rules, with five Events, two that run on every step of the game and three that wait for news.
Every step starts with the Ship. Is there one? Check Instance Count asks, and keeps its answer as isShipThere. If there is, followVX and followVY take its velocity, the Ship’s speed across and down. If there isn’t, after a crash or on the title, they take 0.
The sky doesn’t jump to that velocity. It follows. skyVX is the sky’s own velocity, and on each step it closes part of the gap to followVX. How big a part? followRate, 3, times $deltaTime, the length of one step in seconds. Myth Engine keeps $deltaTime for you, so there’s nothing to make for it. A step is a small slice of a second, so each step closes a small slice of the gap. Far from the Ship’s speed, the slices are big. Close to it, they’re tiny.
Turn the Ship hard, and the sky swings round to follow, smoothly, with no jerk. Stop, and it slows to rest.
The jump field does the same with jumpTarget, at surgeRate, 2.4. That’s the surge. jumpTarget is 1 while a sector jump is on and 0 the rest of the time, and jump eases between the two.
The second Event runs at the end of every step, after the first has done its work. It’s one Repeat, run once for each row of Sky Layers, and here’s the loop that saves six copies.
A Repeat counts its own turns. The count starts at 0, and it’s called local.index, so on the first turn it’s 0, the nebula’s row, and on the last it’s 5, the dust’s. The next five steps all need that number, so Sky Parallax copies it into row, a short, plain name. Then it reads that row’s four numbers.
Then Set Background Sliding Speed gives that row’s Background its speed. Across, it’s the layer’s drift, minus the Ship’s share, minus the surge, which is jump times surge. The Ship’s share is skyVX times depth. A Background slides in pixels of its picture, and the Ship’s velocity is in meters, so pixelsPerMeter, 32, turns one into the other. Down, it’s the same without the surge.
Look closely, and you’ll see the Event never names a single layer. The nebula’s turn comes first and the dust’s comes last, and each turn takes its numbers from its own row. Six turns, one Set Background Sliding Speed, six layers moving.
The last three Events are short. When waveCleared arrives, jumpTarget becomes 1, and the surge begins. When nextWave arrives, the jump is over and jumpTarget goes back to 0. The playStopped Event does the same, so a game that ends in the middle of a jump doesn’t leave the sky racing under GAME OVER.
Every number Sky Parallax keeps from one step to the next, from followVX to surge, is a field of its own small form, Sky Parallax Data. There are eleven, all Numbers, all starting at 0.
Object Data of Logic "Sky Parallax" (its state that lasts between Events).
The sky drifts layer by layer, slides against the Ship's motion by each layer's depth, and surges forward during a sector jump.
Any Objectself.skyParallaxData- Action Name
isShipThere- Object
@self.ship- Operator
>- Value
0
isShipThere.value == true- Component Value
self.skyParallaxData.followVX- Value
@self.ship.transform.velocity.x
- Component Value
self.skyParallaxData.followVY- Value
@self.ship.transform.velocity.y
- Component Value
self.skyParallaxData.followVX- Value
0
- Component Value
self.skyParallaxData.followVY- Value
0
- Component Value
self.skyParallaxData.skyVX- Operator
+=- Value
(self.skyParallaxData.followVX - self.skyParallaxData.skyVX) * @self.followRate * $deltaTime
- Component Value
self.skyParallaxData.skyVY- Operator
+=- Value
(self.skyParallaxData.followVY - self.skyParallaxData.skyVY) * @self.followRate * $deltaTime
- Component Value
self.skyParallaxData.jump- Operator
+=- Value
(self.skyParallaxData.jumpTarget - self.skyParallaxData.jump) * @self.surgeRate * $deltaTime
dataCount("Sky Layers")times- Component Value
self.skyParallaxData.row- Value
local.index
- Component Value
self.skyParallaxData.driftX- Value
data("Sky Layers", self.skyParallaxData.row, "driftX")
- Component Value
self.skyParallaxData.driftY- Value
data("Sky Layers", self.skyParallaxData.row, "driftY")
- Component Value
self.skyParallaxData.depth- Value
data("Sky Layers", self.skyParallaxData.row, "depth")
- Component Value
self.skyParallaxData.surge- Value
data("Sky Layers", self.skyParallaxData.row, "surge")
- Background
data("Sky Layers", self.skyParallaxData.row, "background")- X Speed
self.skyParallaxData.driftX - self.skyParallaxData.skyVX * @self.pixelsPerMeter * self.skyParallaxData.depth - self.skyParallaxData.jump * self.skyParallaxData.surge- Y Speed
self.skyParallaxData.driftY - self.skyParallaxData.skyVY * @self.pixelsPerMeter * self.skyParallaxData.depth
- Component Value
self.skyParallaxData.jumpTarget- Value
1
- Component Value
self.skyParallaxData.jumpTarget- Value
0
- Component Value
self.skyParallaxData.jumpTarget- Value
0
Make Sky Parallax Data first, with Add > Data Structure. Press Add Field eleven times, and type each name from the card. Every field arrives as a Number at 0. So the names are all there is to type.
Then make Sky Parallax, with Add > Logic Component, as an Empty Logic Component like the others. Its four SHARED VARIABLES are all Constant. ship is an Object, with its None button. The other three are Numbers. Press the + on its Data Structures card, and pick Sky Parallax Data under Existing Data Structures. Its row reads self.skyParallaxData, and every path on the card starts with that name.
Step is in the Add Event filter. So is End Step, a little further down the same list.
Check Instance Count takes isShipThere as its Action Name, and its Object list holds @self.ship. Its Operator list starts at >=, so pick >, and type 0 over the 1 in its Value. The If’s condition is isShipThere.value == true, in its one box.
Add inside Then gives the first two Change Component Values, and Add inside Else the other two. Each takes its path typed, then Enter, and then its Value. The first reads @self.ship.transform.velocity.x, the Ship’s speed across, from its Transform. On the Else line, both Values are 0.
The next three go on the Event’s own line, below the If, from Mode 1’s right-click. Their Operator lists start at =. Each needs the card’s +=, which the list writes as Plus. Then type the long formulas whole, brackets and all, as the card spells them.
In End Step, the Repeat comes first. Add it from Mode 1’s right-click. Join it, and type dataCount("Sky Layers") into the Count on its block. Its six steps go in with Add inside Repeat, one at a time, and Connect to sequence joins each. The first Change Component Value takes local.index as its Value. The next four read the table, each with its own column’s name in quotes at the end.
Set Background Sliding Speed’s Background is a list of your six Backgrounds, and its last choice is From a Value. Pick that, then click the Background again, and type the card’s formula, quotes and all. X Speed and Y Speed are boxes, and they take their formulas typed whole.
The Add Event filter already holds waveCleared, nextWave and playStopped. Waves and Play Switch send them.
11.5.2 Game Rules
Last, attach Sky Parallax to Game Rules. Its ship shares one row under Variables with the ship of Lives and Respawn, so it already says Ship. Sky Parallax Data comes along too, as the card’s Data Structure lines show.
Extra ShipsExtra Ships DataHeartbeatHeartbeat DataSky ParallaxSky Parallax DataShipAsteroid LargeWave BannerSaucer LargeSaucer SmallTitle PromptTitle AsteroidPlay Again PromptPausedLeave its switch on. The sky isn’t part of play, so Play Switch never touches it. It drifts on the title, under GAME OVER, and on into the next game.
Run the game. The title is no longer on an empty screen.
Watch the sky for each of these.
- On the title, the six layers drift to the left and a little upward, the near ones faster than the far ones.
- Press Enter and fly right. The dust streams left past the Ship, the near stars slide, and the nebula barely moves.
- Fly up, then down. The sky slides the other way each time, and it swings round smoothly when you turn.
- Stop, and the sky slows back to its own drift.
- Lose a Ship. With no Ship on the screen, the sky eases to its drift.
- Break the last rock of a wave. Every layer rushes left at once, then eases back as the next WAVE banner shows.
- Lose your last Ship in the middle of a jump. The rush eases off under GAME OVER, and the sky drifts on the PLAY AGAIN screen.
Sky Layers holds six layers, one row each. Every step, Sky Parallax eases its own velocity toward the Ship’s. At the end of every step, it runs through the rows and gives each layer its speed: its drift, its share of the Ship’s motion, and the surge. Waves’ waveCleared starts the surge, and nextWave or playStopped ends it.
Underneath is one idea. When many things follow one rule, write the rule once, and put what differs in a table. The six layers differ only in their numbers. So the numbers live in rows, and one loop reads them all.
11.6 If It Didn’t Work
A sky has a lot of small numbers in it, and one of them may be off the first time. That’s normal. Run the game, fly a little, and watch.
The sky is still black? Look at Space’s Screen Backgrounds, under the Scene’s Properties. All six names should be there, Nebula Panorama at the top.
The sky shows, but only one layer, or the dust is behind the nebula? The order in Screen Backgrounds is back to front. Drag each row by its grip until the list matches the card.
Everything shows, but nothing moves? Perhaps Sky Parallax isn’t on Game Rules, or its switch is off. Then look at the End Step Event. Set Background Sliding Speed must sit inside the Repeat, joined, with an arrow into it.
Only the nebula moves, and the others hang still? The Repeat’s Count should read dataCount("Sky Layers"), spelled like the table. And the first Change Component Value inside it needs local.index, so row changes on each turn.
The sky doesn’t follow the Ship? The three Change Component Values at the bottom of Every Step need Plus in their Operator lists, the card’s +=. With =, the sky takes one small slice and forgets the rest.
A layer drifts the wrong way, or races? Look at its row in Sky Layers, where each number should match the card’s, minus signs and all.
The sky never surges? Waves’ No Instances Left needs the Trigger Custom Event that sends waveCleared, from Chapter 10, and Sky Parallax’s waveCleared Event needs jumpTarget set to 1.
The surge never stops? The nextWave and playStopped Events each set jumpTarget back to 0.
Each of these is a 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, finished, if you’d like to compare.
The sky is yours to change. A new layer is a new Background and a new row, and Sky Parallax doesn’t change at all. Duplicate Stars Near in the Resources, and give the copy a row of its own with a depth of 0.3. Add it to the Scene, and drag it up between Stars Near and Space Dust. Or make the jump wilder: double every surge, and clear a field.
And then there’s what comes after this book. You’ve built a whole game, piece by piece, from an empty project. What would you make next? A different sky, a different ship, a game nobody has played yet? You know how to start every piece of it now.
Still stuck? Search the manual, or ask in the Myth Engine Discord (opens a new tab).
In Chapter 1, one Ship sat alone on a dark screen, with no stars yet. Now it flies through deep space, and every rock, saucer and star in it is one you put there.
Free demo
Free
- No time limit
- Build, save and playtest your games
- Follow every game guide and build its game
Publishing needs the full version.
Try the free demoFull version
$84.99 USD, once
No subscription, no paid upgrades, every update included.
Everything in the free demo, plus:
- Publish your game as one HTML file, a web folder, or desktop and mobile projects you build and sign
- Share it or sell it, with no royalties, however much it earns
- Let players build their own version of your game, within the parts you allow (Builder Mode)
Windows 10/11, 64-bit · One person, on computers you own or control · Checkout and downloads through itch.io · Made by 3D Mage
License agreementMac, refunds and other questionsWhy pay for Myth Engine when free engines exist?
