How to create a new Room/Scene?
In this section I will describe all the tools and the work process to create a new full Scene.
- Tiled Map: https://www.mapeditor.org
- Tiled Map Optimizer: https://www.dwdeveloper.com/tiled-map-optimizer/
- Frame Extruder: https://github.com/lgibson02/FrameExtruder
Game creation process
1 - Create the maps!
I've been using Titled for this since it's a great and easy tool to work with.
The most IMPORTANT considerations here are 2:
"How you split the map layers"
Since this will affect if the layers go over or below the player sprint.
The "LAYERS NAME CONVENTION"
This is coming to replace all the collisions and maps data saved in the DB, instead of that we will be using the same JSON map files to load all that information based on which layers are considered for collisions, which ones for change-points, and how they will behave according to the player.
Is important to understand that the layers name conventions are used for both server and client sides.
From this we have the following conventions:
Any layer with this keyword in the name will be used to create blocks used for collisions in the server side. A collision in the server side will be represented by a empty box with the size of a tile, so if you edit your map and hit/collide with an empty space, is probably because you have a tile with a value different from zero in that position in a layer with the word "collisions" on the name.
To avoid this kind of issues I recommend you to use the TiledMap option to "Highlight Current Layer" (available pressing H while editing the map), this way you will easily see if there's any non-empty blocks in any "collision" layer.
Any layer with this keyword in the name will get an incremental depth in the client side, this way the map view will be affected by the layers order in the file and by the layers name that will get the incremental depth, so even when you can see the layers properly displayed in the TiledMap editor you may not get the exact same result after we process the layers to all these over the player.
For example: if you have 5 layers, and the 3rd and 5th in the list have "over-player" in the name, the layers will get the following depth in Phaser:
L1 = depth 0, L2 = depth 0, L3 = depth 1, L4 = depth 0, L5 = depth 2 > where the player sprite will have depth 0 and go over all the other layers, the L3 and 5 will be over the player.
Any layer with this in the name should only have tiles are going to be used as change-points in the server side.
At this time if you used multiple images to create your maps, you will need to merge them in one, for that you can check optimize steps below.
The layers that starts with this keyword will be used for the respawn objects areas and though this layers requires to have content on them to know the valid tiles for respawn, these will never generate collisions.
2 - Optimize the map!
At this point I've realized that have multiple images for a single tile set where I was using just a few parts of each was not the best, so I've decided to create an optimizer (since I didn't found anyone that do exactly what I needed).
So all you need to do at this point is to drop your JSON file and all your images in the tilemap optimizer and get the optimized image and modified JSON file.
3 - Prepare the database
Let's say you have both files for your map ready:
yourmap.png. The first you need to create in the database is a new entry in the
For that you need to run the following query (note: I'm not adding any extensions to the file names):
INSERT INTO `rooms` (`name`, `title`, `map_filename`, `scene_images`) VALUES ('YourMapName', 'Your Map Title', 'your-map-file', 'map-image');
Then you have two options here:
- Set your new room as the default for players start, by updating the initial room config:
UPDATE `config` SET `value` = `[your-map-entry-id]` WHERE `path` = 'players/initialState/room_id';
- Edit one of the current rooms change points in the database, to redirect the user to your new scene (see below how to manage the change points and the return positions in the database).
Just with that you should be able to run the game with your new scene.
4 - Configure change points
The change points are defined in the database and to create a change-point you need to know the tile-index where it was specified in the map file.
How to get the index?
Well... If you are using Tiled it will give to you the tile coordinates, let's say "39,19" (x,y) in a "48x28" tiles map (this will be our ReldensTown map, 39,19 is the door on the blue house), if you take that and do the math:
tileIndex = y * mapW + x >
19 * 48 + 39 you will get the index
951 which is the value you will see for our change-point in the database.
After you got your tile index you only need to insert the change point like (note 1 and 2 will be the origin and next scene ID's, where the change point is and where is going to take you):
INSERT INTO rooms_change_points ('id', 'room_id', 'tile_index', 'next_room_id') VALUES (NULL, 1, 951, 2);
5 - Configure return positions
What are the return point? Basically are the initial scene position that depends on the previous scene.
For example, if you are in the town and go the first house, the first house only has 1 return point saved since your are always coming from a single door in the town, but when you go out from the house 1 you will need to specified at which point of the town you are going, so there you will see two return positions for the town in the database: one is the default that will be always the house 1, and the other will be for the house two.
To create these return positions you only need to specify the position in pixels, if it's the default position of the scene or not, and the scene where that position will be trigger.
A record in this table will look like this:
INSERT INTO `rooms_return_points` (`id`, `room_id`, `direction`, `x`, `y`, `is_default`, `to_room_id`) VALUES (9, 6, 'right', 400, 400, 0, 2);
- The first room_id is where the player will be after the room change, if you go from the town into the house 1 this room_id will be the room_id of the house 1.
- The direction and the X,Y values are the position where the player will be displayed in the map (here is where you need to put the position in pixels), and for last the to_room_id is where the player is coming from.
NOTE: in the next beta the "to_room_id" field will be renamed to "from_room_id" to avoid confusions. Not sure what I was thinking when named the field... right?
I'll improve this documentation over time so if you have questions about this just ping me on discord or send me an email.
All for now!