Building Placeholders and collisions

Now that I’m an expert on tilemaps, today I decided to whip up a quick tileset for making building placeholders. Just some transparent rectangles– not perfect, just for placeholding. This will allow me to start placing items on the map without commiting to the pixel art just yet. It is nice to walk around to get a feel for the sizes and spacing of the various buildings. While I was here I went ahead and figured out collisions (making sure ned can’t walk through walls) and z-indices (allowing ned to walk behind buildings and in front of them when even though all the building placeholders are on the same layer).

In the tileset editor pane, the Z-index of each tile can be set and collision objects can be drawn over each tile (similar to bitmasking). Make sure to give each tile its own collision object and not to draw a single collision object over multiple. The z-index of an object determines its order of rendering on the screen. I set the z-index of tiles at the bottom of the building to -20 (random negative number) and I set Ned’s AnimatedSprite z-index to -1. The default for the rest of the tiles was 0, so this ensured Ned would walk behind the tops of buildings and in front of the bottoms. This isn’t perfect, but I don’t want to waste too much time on the placeholders that won’t actually be in the game!

I also set the z index for the entire roads tilemap to -2000 to make sure they would always be rendered first.

Ned behind a placeholder building [Image: Ned walking around some buildings]

EDIT (2021-12-25): A Better Way to do this

For the actual buildings, I ended making each building its own scene with a sprite node in it to load the texture. I add a collision polygon to the base where I don’t want the player to walk through, and ensure the origin of the sprite node is at position (0,0).

In the script attached to the player node, I add

z_index = position.y

Each building scene that is instanced in the main map scene must be somehow grouped together. They can either all be members of a “Buildings” group, or children of the same parent node. Then in a script, again add this for each building (in a for loop):

z_index = position.y

The z-index of the player changes dynamically: when it is above the origin of a building scene instanced on the map, it will render behind, otherwise it will render in front.

More on my scheme for buildings in the next post.