Most games treat the level as scenery. A digging game turns it into the material you play with — every block you break is really gone, and the ground gives way under you. In Max2D that is one block, Set tile, plus one habit that stops it stuttering. This guide builds the whole loop.
This guide assumes you have painted a tile layer before. If you have not, read how to use tile maps first — it is fifteen minutes and everything below builds on it.
The idea in one block
Set tile writes one cell of a tile layer while the game is running. Give it a tile number and it paints that tile; give it a number below zero and it erases the cell instead. Placing and destroying are the same block.
The important part is what happens next: when a cell changes, that layer rebuilds its collision by itself. The hole you just made is a real hole. Anything standing on the cell falls into it. You do not write any of that.
Step 1: two layers, not one
Build the level as two tile layer objects:
ground— the rock the player digs. Solid tiles.bedrock— the outer walls and the floor of the world. Also solid, but a separate object.
Set tile targets one named layer. Point it at ground and bedrock becomes genuinely indestructible — not "the player probably won't get there", but physically impossible to remove. That is a much better way to bound a level than checking positions at the edges.
Step 2: dig where you point
On the player, add Set tile. Set the layer to ground, switch mode to World, and set the tile number to -1 to erase.
World mode is the part that makes this easy: instead of grid coordinates, it takes a position in the game world. So the x and y fields become "where am I, plus a bit in the direction I'm pointing":
- x — your position x, plus the joystick's x times about 30
- y — your position y, plus the joystick's y times about 30
That single block digs in whatever direction the stick is pushed. Down to descend, sideways to tunnel. There is no separate case for each direction, and nothing to get backwards.
Guard it with a small dead zone — only dig when the stick is actually pushed — or the player will chew through the floor while standing still.
Step 3: give it a speed limit
This is the step people skip, and it is the difference between smooth and stuttering.
Every change asks the layer to rebuild its collision. Once per dig that is nothing. Sixty times a second, on a large map, it is real work and you will feel it.
So add a number variable — call it cool — and:
- If
coolis above zero, subtract one and do not dig. - Otherwise, if the stick is pushed, dig once and set
coolback to about 5.
That caps digging at roughly ten times a second. It is still instant to the player, it costs almost nothing, and it feels better — drilling through rock should take a moment rather than making the ground evaporate.
Once digging has a rate, that rate is something you can tune, upgrade, or vary by material. Slower through obsidian than through soil is one comparison and one number.
Step 4: hazards on a third layer
Lava, water and anything else that should hurt goes on its own tile layer with the tiles set to Trigger. Triggers report a collision but block nothing, so the player sinks into lava instead of standing on it.
On the player: Is colliding with → the lava layer → drain a health variable. Because lava has its own layer name, that check can never be confused with landing on ordinary rock — which it absolutely would be if the lava were painted onto the ground layer.
One thing to watch: that collision is true on every frame you are in the lava. Draining health per frame is right, but playing a sound per frame is sixty sounds a second. Gate the sound behind its own small cooldown, the same trick as the digging.
Step 5: depth as a score
Compare the player's depth to a variable each frame and add one when the depth is greater. Two blocks.
It gives you a clean whole number to display, and it records the deepest point reached rather than where the player is standing now — so climbing back up to escape does not cost you your score. That is almost always what a descent game wants.
Try it: Deeper
The example project is a full descent game: five bands of rock that darken as you go, ore veins, lava pools, wooden one-way platforms across the caves, and a crystal chamber at the bottom about 350 m down.
Open the player object and read its script top to bottom — it is the whole loop in about twenty blocks, with a note beside it explaining each part. Things worth changing: the dig reach (30), the cooldown (5), gravity, and the lava damage rate.
In Max2D: Projects → Import Project → pick the zip. Play it in portrait.
Frequently asked questions
How do I make destructible terrain in Max2D?
Build the terrain as a Tile Layer, then use the Set tile block to erase cells while the game runs. Set tile with a tile number below zero clears the cell, the layer rebuilds its collision automatically, and anything standing on that cell falls. It is one block — there is no separate destructible-object system to learn.
How does Set tile know which cell to erase?
Switch its mode to World and hand it a position instead of grid coordinates. Put your own position, plus however far ahead you are digging, into the x and y fields with the Expression solver. The block converts that position to a cell for you, so you never count cells or worry about where the layer sits.
Why does my game stutter when I dig?
Because you are digging on every frame. Each change asks the layer to rebuild its collision, and doing that sixty times a second on a large map is real work. Add a small cooldown: a number variable you subtract one from every frame, and only dig when it hits zero before resetting it to five or six. That caps digging at about ten times a second, which feels responsive and costs almost nothing. It also makes digging feel like drilling rather than like the ground evaporating.
How do I stop the player digging out of the level?
Put the outer walls and the floor on a second Tile Layer with a different name — bedrock — and only ever point Set tile at the diggable layer. Because Set tile targets one named layer, the walls are physically impossible to remove. This is much more reliable than trying to check the player's position against the edges of the map.
How do I make lava hurt the player?
Put lava on its own Tile Layer and set the lava tiles to Trigger. Triggers report a collision without blocking movement, so the player sinks into it rather than standing on it. On the player, use Is colliding with pointed at the lava layer, and drain a health variable while it is true. Because the lava has its own layer name, that check can never be confused with landing on ordinary ground.
How do I show how deep the player has got?
Keep a number variable and only ever let it go up. Every frame, compare the player's depth to the variable, and if the depth is greater, add one. That gives you a whole number to display — no decimals — and it naturally records the deepest point reached rather than where the player happens to be now, which is what a score should be.