How to Create Multi-Room Layouts For a 2D Game Using Arrays

4

Index

Stats

1,908 visits, 5,115 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY-NC 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 16 Nov, 2022.

This, in my opinion, is the most fun part. Start off by renaming the current layout (it should be the only layout right now). Name it what you named the spawn room in the array. Make sure they are identical or the game will not recognize which room you are in (how it does this at all comes later).

Once your layout is named properly, you can begin actually adding things to the room. The first thing you will probably want to add is walls; otherwise the player can simply leave the room from any point. This is important, however: the player does need to be able to leave the layout. This is how the game will know you have moved to a different room.

The walls are simply to control where the player can leave the room. You can create these walls in a number of ways; if you are in a hurry or just wanting to practice, you can just use Sprite object with the Solid behavior positioned along the edges of the room. If you are more patient and/or want a nicer look, you can use a Tilemap object (also with the Solid behavior) and draw around the edges of the room. Obviously, make sure whatever you use for the walls provides at least one exit or the player will never be able to leave the room.

Where you put that exit is important. The exit needs to be at the connection between the current room and the next room in the array that you want the player to go to, so for instance, if you want the player to leave their current room and go one room down, the exit should be downward.

Once you are satisfied with your room's walls, create another layout, name it after another cell from the array, and do the same thing. Create and rename another layout for every cell in the array that contains a room name. Make sure that all your layouts' names properly match their corresponding array cells, and make sure that all of the walls and exits connect to each other properly. It helps to envision the array as a map of every room, with walls around the edges of each cell and exits connecting to another room.

Every room should be connected to another room, unless you don't want the player to be able to access it directly.

You will probably end up with a lot of layouts. That is perfectly normal and 100% okay, especially if your game is large.

You can resize any of your layouts. In fact, doing this will give a good sense of variety to your game and make it feel less like a bunch of squares all laid out in a grid (even though that's exactly what the array is). Just make sure to consider how the dimensions of that room will affect the rooms around them and whether or not certain connections will make sense.

When you're done adding rooms, it's time to get into some technical stuff again.

  • 0 Comments

Want to leave a comment? Login or Register an account!