Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

GMRoomPack

Package GameMaker rooms and load them as you please · By YellowAfterlife

Need help with tilemaps and layers

A topic by Phoebii created Jun 10, 2019 Views: 683 Replies: 9
Viewing posts 1 to 8

Hello, I have just bought your product, and I'm trying to implement it.

I've run  into problems with layers and tilemaps.

Problem 1:

How do I get correct tilemap ID's for tile collision checking?

For example, this code:

I created a tilemap list - global.tilemap_list - using room_pack_store_tilemaps() , and m_pos_collisions is equal to 2. This works until I try to load another room because I assume tilemap_list changes.

How do I always get correct tilemap for my collision checking and other purposes?

Problem 2:

I need layers for depth sorting and loading rooms seem to mess this up - it doesn't work anymore.



So the main problem is that I don't know what room loading does to layers.

Developer(+1)

GMRoomPack tries to find room's each layer by name (via layer_get_id), and, if there isn't one, creates it at the original depth.

Needless to say, this makes issue #2 a bit mysterious - perhaps you are loading a room with another controller object and GM declines to create duplicate layers? I'd suggest to try logging IDs of your grid layers.

As of issue #1, are you loading multiple tilesets into the same room? You might need to store the actual tilesets into a separate list (and loop over them) but it's hard to tell with this little context.

"GMRoomPack tries to find room's each layer by name (via layer_get_id), and, if there isn't one, creates it at the original depth."

So if I made sure that packed room and room in which packed room is loaded to have layers with same names, the "layer_get_id" would work properly?

Currently instance layers have different names - "Instances" and "sort_begin".

"As of issue #1, are you loading multiple tilesets into the same room? You might need to store the actual tilesets into a separate list (and loop over them) but it's hard to tell with this little context."

Yes, I'm loading 2 tilesets. What else do you need to know?

"Needless to say, this makes issue #2 a bit mysterious - perhaps you are loading a room with another controller object and GM declines to create duplicate layers? I'd suggest to try logging IDs of your grid layers."

Okay, I'll do that the next day.

Developer(+1)

Of #1, I feel like the issue could be either that or that GM declines to make several layers at the same depth - so you'd want to either match the layer names, or adjust their depths to not clash. However, adding multiple tilemaps to the same layer is still OK

(1 edit)

EDIT:

It works!

Problem 1:

I finally got to logging layers (+DS list with tilemaps stored with room_pack_store_tilemaps) -



This cleared up some confusion: Tilemaps don't have to be assigned to layers.
So I figured out how to get tilemap names and came up with this code:



It runs whenever room is loaded and stores correct tilemap positions in tilemap_list.

Now I need to create two tilemap lists, because I need two rooms loaded, and whenever room is loaded, it creates new tilemaps - currently I store just the last loaded room's tilemaps - the other room's collisions stop working.

If two tilemap lists will work, it'll be done. I hope I'm not doing something horribly wrong.

This is the code I use to log layers, just in case:



Problem 2:

I managed to fix it - the problem was that loaded room object create events fails to set layers, probably because of how room loading works.
(1 edit)

I'm having similar issues to this. My structure is like so:

room_init - loads first takes care of prerequisite loading initialization

room_world - loads skeleton room with all the engine code (lighting, client, etc)

obj_world is also loaded in room_world and takes over the rooms loading process based off the players positioning information. When I load the room_pack data I process it to split my world up into a chunk grid, I rewrite the layers name to "layer_name + chunk_id" and cuts out any instances that aren't within the chunks boundaries (tiles are excluded the tiles are loaded separately). This is technically only 1 room cut up into multiple room data chunks that room_pack should be able to understand. This works sort of. The first chunk loads with all its instances (I excluded the tile layers since they aren't relevant I think):

Layer [layer_engine(7)] - Layer ID: 10 - Depth: -10099 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_light(1)] - Layer ID: 11 - Depth: -9999 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_shadow(1)] - Layer ID: 12 - Depth: -9899 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_client(1)] - Layer ID: 13 - Depth: -9799 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_player(0)] - Layer ID: 14 - Depth: -9699 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_interaction_1(23)] - Layer ID: 40 - Depth: 1100 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_npc_1(0)] - Layer ID: 39 - Depth: 1200 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_exterior_1(118)] - Layer ID: 38 - Depth: 1300 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_floor_1(15)] - Layer ID: 37 - Depth: 1400 - Tilemap<undefined> - Tilemap ID: -1

instance_exterior_1 / instance_floor_1 are chunk ones instances.

Then when the chunk next to it loads this happens:

Layer [layer_engine(7)] - Layer ID: 10 - Depth: -10099 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_light(1)] - Layer ID: 11 - Depth: -9999 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_shadow(1)] - Layer ID: 12 - Depth: -9899 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_client(1)] - Layer ID: 13 - Depth: -9799 - Tilemap<undefined> - Tilemap ID: -1
Layer [layer_player(0)] - Layer ID: 14 - Depth: -9699 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_interaction_1(23)] - Layer ID: 40 - Depth: 1100 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_npc_1(0)] - Layer ID: 39 - Depth: 1200 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_exterior_1(7)] - Layer ID: 38 - Depth: 1300 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_floor_1(0)] - Layer ID: 37 - Depth: 1400 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_interaction_5(0)] - Layer ID: 98 - Depth: 1500 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_npc_5(0)] - Layer ID: 97 - Depth: 1600 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_exterior_5(0)] - Layer ID: 96 - Depth: 1700 - Tilemap<undefined> - Tilemap ID: -1
Layer [instance_floor_5(21)] - Layer ID: 95 - Depth: 1800 - Tilemap<undefined> - Tilemap ID: -1

So you can see that chunk 5 loads 21 instances to the floor but now its showing that the instance_floor_1 now as 0 elements and the instance_exterior_1 has 7, which is very strange. This is how I'm loading the room_pack map chunks:


Any help is greatly appreciated!

Thanks!

Developer

If you can email me a sample project where things are misbehaving, I will take a look

Sent you an email, thanks!

In fact its not after I call room_pack_load_map even if I print the layers from my client object when I'm adding my player all those layers no longer have elements.

For me this issue turned out to be because I was setting the depth of my instances after they had loaded it was putting them into a new temporary layer.