Appearance
Making a 2D Game
New in MNodes 1.1.8
The Scene 2D nodes are new in MNodes 1.1.8. Older versions do not have them, so a project that uses them needs 1.1.8 or newer.
MNodes can make a whole 2D game with no code: a platform game seen from the side, or an adventure seen from above. You paint the level, choose who is in it and how each one moves, and wire what happens in the game into the rest of your patch: a score, lives, music that changes, a sound on every jump. This page explains how the pieces fit together, then shows how to build the usual parts of a game, one recipe at a time. Every setting is described in the Scene node reference.
Start in one minute
- Add a Scene 2D World.
- Select it and press Add at the bottom of its body, then A Game. A Scene, a hero and a camera are added beside it and wired to it.
- Click the Scene and play: the arrow keys (or A and D) walk, Space jumps. A game controller works too, with no setup.
With several games in one project, only the one you clicked last hears the keys and the game controller. A border in the colour of your theme shows which one, and Esc lets go of it. A project with one game always hears them.
Now select the World again. Pick a kind of tile in the palette along the top of its body (Rock, Ledge, Water, Spikes, Coin...) and click or drag over the level to paint it. A right-click erases. Start is where the hero begins. Every stroke can be undone.
The hero, the enemies, the items and the crates wired into the World are drawn on its body too, where they start. Drag one to move it: drag the hero to move the Start.
How the pieces fit
Think of a puppet theatre. The World is the stage, the Characters are the puppets, and the Scene is the window you watch it through. Everything that lives in the level is wired into the World's Objects input, and the World is wired into a Scene.
Character ─┐
Body ├─► Scene 2D World ─► Scene
Item │
Camera │
Background │
Tileset ─┘
Sprite ─► Character (its Sprite input)| Node | What it is | Wire its Object into |
|---|---|---|
| Scene 2D World | The level: its tiles, its physics, up to eight levels with doors between them, seen from the side or from above. | A Scene's Objects |
| Scene 2D Character | Someone in the level: the hero, an enemy, someone to talk to. | The World's Objects |
| Scene 2D Sprite | What characters look like, kept apart so several can share it. | A Character's Sprite |
| Scene 2D Body | A crate, a ball, a platform that moves by itself. | The World's Objects |
| Scene 2D Item | Something to pick up: a gem, a key, a heart, a sword. | The World's Objects |
| Scene 2D Camera | How the view follows the hero. | The World's Objects |
| Scene 2D Background | A picture behind the level, or in front of it. Up to six. | The World's Objects |
| Scene 2D Tileset | A picture of tiles of your own to paint the level with. | The World's Objects |
A Scene 2D Enemy is a Character that starts as an enemy.
Six ideas behind everything
1. Everything counts in tiles. A Speed of 7 walks seven tiles a second. A Jump Height of 4 jumps four tiles high, whatever size a tile is drawn at. The World's Tile says how many pixels a tile is on the screen, and a Gravity of 1 pulls as on Earth, a tile being a metre. A level painted with small tiles and one painted with big ones play the same.
2. The level is painted, and each kind of tile does something. Rock stops whatever moves. A Ledge is a thin platform you jump up through. Water is swum in, Ice is slippery, a Spring throws the hero up, and Spikes send it back to safe ground. Coins are collected, a Goal ends the level, a Checkpoint is where the hero comes back to, and an Exit is a door to another level. Bricks and Prize blocks are hit from below, a Lock needs a key, a Ladder is climbed, and a Crumble floor falls away. All the kinds are in the World's reference. With a Tileset, each of its pictures is one of these kinds too.
3. Control says who moves a Character. Each Character has a Control:
- Player: you, with the keys and a game controller, no cable needed. This is the hero.
- Enemy: it walks by itself and hurts the hero. Jump on it to stomp it.
- NPC: someone in the level who never hurts. The hero talks to it.
- Patch: only its cables move it (Left, Right, Jump, Walk...), from buttons, a MIDI keyboard or anything else.
4. The game tells you what happens, and your patch decides what it does. The World, the Characters and the Items send out an Event each time something happens: the World's Coin, Hurt, Goal, Checkpoint and Exit, a Character's Jump, Land and Died, an Item's Picked. Nothing counts a score or lives by itself. You wire these into the nodes you already know (a Stepper to count, a Scene Text to show, a sound to play, music that changes), and that is what makes your game yours.
5. Something sent back comes through another node. A node is never wired to itself. To make the World do something when the World says something (save at each checkpoint), go through a Float: Checkpoint into a Float, and the Float into Save.
6. A node shows what you use. The World and the Characters have many inputs and outputs, and most of them show only once they have a cable, so the nodes stay small. To wire one you cannot see, such as a Character's Died or the World's Save, select the node and turn on Inputs (what goes in) or Events (what comes out) in the Rows section of its Inspector: every row shows. A row with a cable stays, so you can turn them off again afterwards.
Recipes
A platform game, seen from the side
- Start with Add, then A Game on a World (above), and paint the level.
- For a level bigger than the screen, set the World's Width and Height in tiles. The camera follows the hero.
- Add a Scene 2D Background for a sky, and another for mountains far away with a Parallax of 0.2, so they move less than the ground.
- For more levels, press + at the bottom right of the World's painter and paint the next one. An Exit painted with a 2 takes the hero to level 2. What you add with Add while you paint level 2 is only in level 2.
Placing things, level by level
- Select the World. Its painter shows the hero at the Start, and each enemy, NPC, item and crate wired into the World where it starts, as it looks in the game.
- Drag one to move it, tile by tile. Every drag can be undone.
- Each enemy, NPC, item and crate is in one level, or in all of them. Right-click it on the painter and choose All Levels or a level, or set its Level row, which shows on the node once the World has more than one level.
- Add puts what it makes in the level you are painting. The arrows at the bottom right of the painter go from level to level, each with its own enemies, items and crates. Whatever is wired in by hand starts in all levels.
An adventure, seen from above
- Set the World's View to Top Down. Nothing falls now, and the hero walks every way.
- Paint the ground under everything on the Floor (at the bottom of the painter), and the walls, trees and water on the Level.
- On the hero, Moves chooses 4 Ways (one way at a time, as the first adventure games) or 8 Ways. Space or the controller's A swings its sword, or talks to someone beside it.
- Set the World's Camera to Room by Room: the view slides from room to room. Turn on its Events and wire its Room into an Adaptive Music, and each part of the level has its own music.
A score on the screen
- Add a Stepper for the score, with Min 0 and a big Max.
- Wire the World's Coin into a Float set to 10, and the Float into the Stepper's Add: each coin adds 10.
- Wire the Stepper's Count into a Prepend Text with the Prefix "Score ", and that into a Scene Text's Text.
- Wire the Scene Text into the Scene's Objects, not into the World, so it stays still over the game.
Other things earn points the same way: an Item's Picked, an enemy's Down.
Lives and Game Over
- The hero has Health (in its Inspector): how many hurts it takes before it dies. At 0 it falls, Died goes out, and a moment later it is back at its last checkpoint.
- Turn on the hero's Events and wire its Died into a Stepper's Down, with Min 0, Max 3 and Set 3: three lives.
- Turn on the World's Inputs and wire the Stepper's Min Hit into its Pause: at 0 lives everything stops.
- A Widget Button's Event into the World's Restart and into the Stepper's Reset Max starts again with three lives.
Show the lives with a Prepend Text and a Scene Text, as for the score.
Menus: a title screen, a pause menu, options
A Scene Game Menu is a menu played with the arrow keys, Enter and Esc, or a game controller (and the mouse). While it is open, the hero stands still.
- Add a Scene Game Menu and wire its Object into your game's Scene. Write its Items: Start, Options, Quit. It is open when the project opens (Starts Open): your title screen.
- Turn on the World's Inputs. Wire the menu's Open into the World's Pause, so the game waits behind it, and its Start into the World's Restart. Choosing Start closes the menu and the game begins.
- For a pause menu, add another one with Resume, Options and Quit, its Title Paused, Starts Open off and Opens With on Pause Keys. Wire its Open into the World's Pause too. P or the controller's Start open it, and Resume, Esc or B close it.
- For options, add a third one with
Music: 0 to 10 (8)and Back, Starts Open off. Wire the Options of the other two straight into its Open: it opens over the menu you were in, and Back goes back there. Wire its Music into a Volume's level for your music. - For a game over, wire the lives Stepper's Min Hit into the Open of a menu titled Game Over, with Try Again wired into the World's Restart.
Enemies
- Add a Character and set its Control to Enemy, or add a Scene 2D Enemy. X and Y say the tile it starts on: drag it on the World's painter to move it.
- Walk is the way it sets off, Speed how fast it walks, and with Edges on it turns round instead of walking off a ledge.
- In its Inspector you can make it follow the hero, jump, fly, shoot, or take several hits.
- Stomped, Shot Down and Down say what happened to it, for points or a sound. The World's Hurt says the hero was hurt.
Someone to talk to
- Add a Character with its Control on NPC, standing where X and Y say (or drag it on the World's painter).
- When the hero stands beside it and presses Up (or Space, seen from above), Talk goes out.
- Wire Talk into a Text holding the line it says, and the Text into a Scene Text over the game.
- Near is 1 while the hero is close, for a hint such as "Press Up".
Keys and locked doors
- Paint the door with Lock tiles. A door two tiles tall needs one key.
- Add a Scene 2D Item named key, and drag it on the World's painter to where the key should be.
- Turn on the World's Inputs and wire the Item's Picked into its Key. The hero walks into the lock with the key and the door opens.
Your own keys, buttons and actions
Select the hero and open the Controls page of its editor, the tab beside Look.
- Each thing it does (walk, jump, dash, shoot...) has a row with its keys and its controller buttons. Click one and press the key or button you want instead. + adds another, so Jump can be Space and W at once. A right-click takes one away.
- + Add Action makes an action with a name of your own, such as Magic, Run or Open, and waits for its key. Pressing it sends its name out of the hero's Action and then Pressed. Letting go sends its name and Released. Wire them to anything: a sound, a shot of your own, a door.
- Name an action like one of the sprite's states (a "wave" state, an "attack" state) and holding the action plays that state, with no cable.
- For two players on one keyboard, give each hero its own keys. Each hero can also follow its own controller (Pad).
The hero reads the controller by itself. The Gamepad node is for everything else in your patch: a filter on a stick, a sound on a button.
A look of your own
- No art? Press Make on the bottom line of the hero's editor. Pick a Hero, a Knight, a Wizard, a Slime, a Robot or a Cat, change its colours and its look, and press Use It. It walks, jumps, falls, crouches, gets hurt and dies, all set up for you.
- Your own sheet: drop a picture of frames side by side on the editor, then pick the frames of each state: Idle, Walk, Jump, Fall, Land and the rest.
- The same look on many characters: put it in a Scene 2D Sprite and wire the Sprite into each one's Sprite input (turn on the Character's Inputs to see it). Change the Sprite, and they all change. To start from the hero's look, the World's Add, then A Look for the Hero, puts it in a Sprite wired into the hero.
- States of your own: press + among the states (wave, cheer) and give them frames. A Character's State input plays one by its name (turn on its Inputs to see it).
The blue box in the editor is what the character bumps into, and the picture is what you see. Each has its own size.
Sounds and music
- A Character sends Step, Jump, Air Jump, Land, Bump and Shot at their own moments. Turn on its Events and wire them into whatever plays a sound in your patch.
- The World's Hit and Strength, with its Events on, play a crate landing, harder or softer.
- A Mark painted in the level sends its number out of the World's Mark as the hero passes it, unseen. Wire it into an Adaptive Music to change the music halfway along a level.
Moving platforms and crates
- A Scene 2D Body on Dynamic is a crate the hero pushes.
- On Moving, with a Travel X (across) or Travel Y (down, below 0 up), it goes back and forth by itself and carries whoever stands on it: a ferry, a lift.
Saving the game
- Give the game a name in the World's Game (in its Inspector).
- Turn on the World's Inputs. Wire its Checkpoint into a Float set to 1, and the Float into its Save: it saves at each checkpoint.
- A Widget Button's Event into the World's Load is a Continue button.
The save is kept on this computer, apart from the project, so a project you share starts fresh for whoever opens it.
Where to go next
- The Scene node reference describes every setting of every Scene 2D node.
- Start with Scene explains the Scene itself: the canvas your game is drawn on, and how to put it on the Front Panel.
