Legacy GM [SOLVED] Changing Room's Tileset

K

Kanto Ruki

Guest
Is there a method that can be used to change the room's current tileset? I wish for when the player changes their element (from Grass to Fire for example) that the room changes from a grass theme to a fire theme via tileset and code. I wish not to create objects with a bunch of code in them, rather have some code dictate what tileset is used.
 
A

Aura

Guest
Welcome to the GMC~♫

In the room editor, you can put the tilesets at different depths and then take help of tile_layer_show() and tile_layer_hide() to hide all the tiles at the current tile depth layer and show tiles of the new depth layer. For instance, if you have the fire tiles at depth 1000 and grass tiles at depth 900, you can do this to convert to the grass word:

Code:
tile_layer_hide(1000); //Hide fire tiles
tile_layer_show(900); //Show grass tiles
 
K

Kanto Ruki

Guest
Welcome to the GMC~♫

In the room editor, you can put the tilesets at different depths and then take help of tile_layer_show() and tile_layer_hide() to hide all the tiles at the current tile depth layer and show tiles of the new depth layer. For instance, if you have the fire tiles at depth 1000 and grass tiles at depth 900, you can do this to convert to the grass word:

Code:
tile_layer_hide(1000); //Hide fire tiles
tile_layer_show(900); //Show grass tiles
Thank you~♫

This works great! I just wish that I didn't need to make the level multiple times just to achieve this. I have used GameMaker before but I haven't played with coding before (Not sure if earlier free versions had this option open). So I'm new to the code and using keywords to find code snippets.

But I have come across the interesting piece of code that is tile_set_background(index, background), it sounds like something that will do exactly what I hope for, but I have no clue how to execute properly. Time to look it up now ( >* w* )>

Unless someone knows what this actually does and can provide an example that clarifies my understanding (the manual doesn't give a very clear example)

EDIT: Ya... I'm having little success in learning how to use this properly, does anyone know how to use it?
 
Last edited by a moderator:
A

Aura

Guest
You can use tile_set_background() as well, but that would require you to loop through each tile; which is not the fastest approach. Besides, I have personally always worked with layers to achieve that, so I usually spam people with that suggestion. ^^"

Either way, you would have to rearrange tiles of both the tilesets (backgrounds) in such a way that each tile position corresponds to the same thing. For instance, tile at the top-left corner (tile at the (0,0)th position) in both the tilesets would represet a brick and the (5,6)th tile in both of them would represent mud; and so on. Hope that explains what I mean by "rearranging" the tiles. After that is done, you need to make sure that tiles of both the tilesets are of the same size, or you might get inconsistent results.

Now you would require a list of all the tiles that you want to take into account. If you don't use tiles for something other than crafting the environment, use tile_get_ids() to get an array populated with the tile IDs. If that is not the case, use tile_get_ids_at_depth() to get the array, populated with tile IDs of the depth layer that you'd want to reserve for the environment. I'd use the latter, because habits. ^^"

Code:
var tiles = tile_get_ids_at_depth(900);
for (var i = 0; i < array_length_1d(tiles); i += 1) {
   tile_set_background(tiles[i], bg_Grasstileset);
}
 
A

anomalous

Guest
You can do this, and you were on the right track.
Use background_assign instead, this assigns the entire background to another one.

* edit, both backgrounds don't need to be dynamic...only the new one...thanks for correction Theou

If you organize your tiles and layers/depths well (and are able to), this should not be any significant issue for texture swapping either...but be aware each dynamic resource you create (duplicate and assign), is its own texture page.
 
Last edited by a moderator:

TheouAegis

Member
You can use the normal Room Editor to place the tiles, then just use background_assign() to change the background. If they changed that in studio, then it was another one of their big mistakes. I used background swapping all the time in my GM8 projects.
 
K

Kanto Ruki

Guest
I finally got around to playing with the background_assign and SUPER YES! This is what I was looking for! I created a tileset that I can use to draw out a level, then do background_assign(areaEmpty, areaElement) and basically use this to switch the texture of the level! I just have to remember to run this code in the "Creation Code" in each room.

Thank you TheouAegis and anomalous! And thank you Aura for your help too!
 
Top