Skip to content
Download

Scenery with tiles

You want to build the level by painting the floor and the walls, without dragging an object for every block.

  1. Tileset. Import the image of the tiles as a sprite, slice it to the tile size and create the tileset with + › Novo tileset… (new tileset). In its tab, click the tiles that are solid (floor, wall).
  2. Layer. In the Camadas panel, + Camada › Tiles. Name it Chao.
  3. Paint. Choose a tile in the Inspector’s palette and drag in the room. The right button erases.

The full step by step is in Tileset and tiles.

Nothing changes. The platformer player is the same as when the floor was a solid object:

void Player::onUpdate() {
hspeed = axis("esquerda", "direita") * 1.5f;
if (pressed("pular") && onGround()) vspeed = -4.5f;
moveAndStop();
}
  • The tiles marked as solid in the tileset block movement, like an object with Sólido (solid) checked.
  • moveAndStop() stops at the tile, and onGround() sees the tile under the player.
  • Collision is done through the grid, looking only at the tiles the player’s box touches. A big level, full of tiles, does not get slower.

Decorations that do not collide. Create another Tiles layer, Enfeites, and turn Colide (collides) off in the Inspector. Paint the grass, the flowers and the signs on it.

Knowing which tile the player is on. tileAt returns the number of the tile at a point (or -1 if there is no tile), and solidAt tells whether there is something solid there:

if (tileAt("Chao", x, y + 12) == 7) Audio::play("passo_na_pedra");
if (solidAt(x + 10, y)) flipX = !flipX;

Edges and corners by themselves. Mark a terrain in the tileset and use the terrain brush. See Tileset and tiles.