I’d like to see something around common patterns for starting games in MakeCode. For example this post is geared for “Scene Management”.
I wouldn’t say I’m an expert at all with game design or MakeCode Arcade itself but I have rolled a few custom patterns as I build games and thought it would be useful to share and if possible get some feedback on other ways people have managed these patterns.
Scene Management
You could imagine a “Scene” as a game-within-a-game. But often seen as things like the title screen, menu screen, level 1, level 2, etc.
Quite often I see students using variables for this, and I feel this is the most straight forward and easiest way to do it… but it’s a bit messy and starts to spiral into a pile of if/else blocks for scenes. The biggest thing that students run into is the “cast on null” because they are in a scene that hasn’t yet initialized something like a sprite:
Right now that’s how I push them down this path, we aren’t getting super in-depth games with many many scenes or levels so this typically works well enough for the short classes I run. But for larger games with many levels or many scenes, what is your typical routine for managing scenes in block code?
Note: I tend to try and stay away from custom extensions for such things as it’s difficult to teach when “it’s just done for you” and just entering in a custom url is almost too much for people. So yes there may be a “just use this extension” but that’s not where I’m trying to get. The goal is to learn some solid patterns for these types of problems, not “pull it off the shelf someone else figured it out” kind of thing.
Does anyone have a nice way to handle scene management in the block coding aspects or should I push students that have leveled up to “I would like a title screen” to move to javascript? The “classes” aspects with constructors and destruction are not available in stock blocks. And maybe that’s on purpose, the idea of using blocks as a basic first step into learning how to build things, javascript/python are the next step.
Javascript Version
For some of my bigger games that I write in Javascript I tend to basically do the same thing. You can call this a “state machine” if you’d like. But at the top level I have a large state machine that says “if you are in title and you want to change to a new scene, you can only go to these”.
Here’s a diagram of how the JS structure works:
The general idea:
- Each “scene” is it’s own class, with private variables so that not everything is “global”.
- This allows each scene to manage it’s own sprites, assets and controller handlers.
- Each scene MUST keep track of things it creates and controller button it uses, thus must destroy anything it creates
- When you request a change of scene from one to the next, the global scene switcher handles that by calling the “destroy” function of the current scene then the constructor of the new scene.
This structure really helps keep things separate, and if good enough you can split the work amongst other developers to create their own scenes!
If you’d like to see the actual code for this:


