• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Need Help: Replace tiles with other tiles in-game

J

Jaydors19

Guest
Hi, I'm working on a game that changes seasons. it's just a basic RPG. So the grass tiles I wanted to be changed to snow tiles, for example when I press the letter "P", for example during testing. All of the tiles in the room; not just specific ones at specific locations; literally all of them. Can this be done in GML? Does it matter if they're on different layers? Or does it only matter that I have the names of the tiles?

Example:
Change all 'Tile_Grass' to 'Tile_Snow'
 
Last edited by a moderator:

Slyddar

Member
If you have 2 tilesets, you can simply swap between them by pressing P with something like this:
The tile layer here is "Tile" and the 2 tilesets are t_tileset and t_tileset1.
Code:
if keyboard_check_pressed(ord("P")) {
    var lay_id = layer_get_id("Tile");
    var tile_id = layer_tilemap_get_id(lay_id);
    if tilemap_get_tileset(tile_id) = t_tileset tilemap_tileset(tile_id, t_tileset1);
    else tilemap_tileset(tile_id, t_tileset);
}
 
Last edited:
J

Jaydors19

Guest
If you have 2 tilesets, you can simply swap between them by pressing P with something like this:
The tile layer here is "Tile" and the 2 tilesets are t_tileset and t_tileset1.
Code:
if keyboard_check_pressed(ord("P")) {
    var lay_id = layer_get_id("Tile");
    var tile_id = layer_tilemap_get_id(lay_id);
    if tilemap_get_tileset(tile_id) = t_tileset tilemap_tileset(tile_id, t_tileset1);
    else tilemap_tileset(tile_id, t_tileset);
}
Can this be done in Game Maker 8? The layer_get_id is GMS.
 

TheouAegis

Member
http://gamemaker.info/en/manual#tile functions

Tiles
As you should know you can add tiles to rooms. A tile is a part of a background resource. Tiles are just visible images. They do not react to events and they do not generate collisions. As a result, tiles are handled a lot faster than objects. Anything that does not need events or collisions can best be done through tiles. Also, often one better uses a tile for the nice graphics while a simple object is used to generate the collision events.
You actually have more control over tiles than you might think. You can add them when designing the room but you can also add them during the running of the game. You can change their position, and even scale them or make them partially transparent. A tile has the following properties:

  • background. The background resource from which the tile is taken.
  • left, top, width, height. The part of the background that is used.
  • x,y. The position of the top left corner of the tile in the room.
  • depth. The depth of the tile. You can choose any depth you like, making tiles appear between object instances.
  • visible. Whether the tile is visible.
  • xscale, yscale. Each tile can be drawn scaled (default is 1).
  • blend. A blending color used when drawing the tile.
  • alpha. An alpha value indicating tile transparency. 1 = not transparent, 0 = fully transparent.
To change the properties of a particular tile you need to know its id. When you add tiles when creating rooms the id is shown in the information bar at the bottom. There is also a function to find the id of a tile at a particular position.
The following functions exist that deal with tiles:



tile_add(background,left,top,width,height,x,y,depth) Adds a new tile to the room with the indicated values (see above for their meaning). The function returns the id of the tile that can be used later on.
tile_delete(id) Deletes the tile with the given id.
tile_exists(id) Returns whether a tile with the given id exists.

tile_get_x(id) Returns the x-position of the tile with the given id.
tile_get_y(id) Returns the y-position of the tile with the given id.
tile_get_left(id) Returns the left value of the tile with the given id.
tile_get_top(id) Returns the top value of the tile with the given id.
tile_get_width(id) Returns the width of the tile with the given id.
tile_get_height(id) Returns the height of the tile with the given id.
tile_get_depth(id) Returns the depth of the tile with the given id.
tile_get_visible(id) Returns whether the tile with the given id is visible.
tile_get_xscale(id) Returns the xscale of the tile with the given id.
tile_get_yscale(id) Returns the yscale of the tile with the given id.
tile_get_background(id) Returns the background of the tile with the given id.
tile_get_blend(id) Returns the blending color of the tile with the given id.
tile_get_alpha(id) Returns the alpha value of the tile with the given id.

tile_set_position(id,x,y) Sets the position of the tile with the given id.
tile_set_region(id,left,top,width,height) Sets the region of the tile with the given id in its background.
tile_set_background(id,background) Sets the background for the tile with the given id.
tile_set_visible(id,visible) Sets whether the tile with the given id is visible.
tile_set_depth(id,depth) Sets the depth of the tile with the given id.
tile_set_scale(id,xscale,yscale) Sets the scaling of the tile with the given id.
tile_set_blend(id,color) Sets the blending color of the tile with the given id. Only available in the Standard Edition!
tile_set_alpha(id,alpha) Sets the alpha value of the tile with the given id.
The following functions deal with layers of tiles, that is, collections of tiles at the same depth.



tile_layer_hide(depth) Hides all tiles at the indicated depth layer.
tile_layer_show(depth) Shows all tiles at the indicated depth layer.
tile_layer_delete(depth) Deletes all tiles at the indicated depth layer.
tile_layer_shift(depth,x,y) Shifts all tiles at the indicated depth layer over the vector x,y. Can be used to create scrolling layers of tiles.
tile_layer_find(depth,x,y) Returns the id of the tile with the given depth at position (x,y). When no tile exists at the position -1 is returned. When multiple tiles with the given depth exist at the position the first one is returned.
tile_layer_delete_at(depth,x,y) Deletes the tile with the given depth at position (x,y). When multiple tiles with the given depth exist at the position they are all deleted.
tile_layer_depth(depth,newdepth) Changes the depth of all tiles at the indicated depth to the new depth. With this function you can move whole tile layers to a new depth.
 

TheouAegis

Member
You need to get the id of the tile using tile_layer_find(), then set its region using tile_set_region(). Unlike in Studio, tiles aren't bound by a width and height.
 
J

Jaydors19

Guest
You need to get the id of the tile using tile_layer_find(), then set its region using tile_set_region(). Unlike in Studio, tiles aren't bound by a width and height.
Ah, so Game Maker cannot perform the task I am seeking. Thanks for trying to help anyway
 

TheouAegis

Member
Ah, so Game Maker cannot perform the task I am seeking. Thanks for trying to help anyway
actually if you read through everything that I posted, you would see that it could be done. Quite easily. I didn't read your first post thoroughly enough, so I gave you the wrong functions in my last post. All you need to do is change the background associated with that tile layer. That's also how you would animate tiles as well.
 
J

Jaydors19

Guest
actually if you read through everything that I posted, you would see that it could be done. Quite easily. I didn't read your first post thoroughly enough, so I gave you the wrong functions in my last post. All you need to do is change the background associated with that tile layer. That's also how you would animate tiles as well.
When It finds the ID of a single tile, is that the ID for the tile throughout the entire map? I have 500 of the tile "tile_grass" scattered all over the map (distributed between 3 layers), and i want to change all of them to "tile_grasswithsnow". I re-read what you posted, but haven't been able to figure out. I'm not good at GML apparently lol Am I doing this wrong? Should I just keep groups of tiles in their own layer and not mix them in other layers?
 
Last edited by a moderator:

TheouAegis

Member
Man, i i haven't used GM8 in so long...

It's a lot more work, but if you have a layer of normal tiles, then another layer of snowy tiles, then hide the snowy layer until it snows, at which time you hide the normal layer and show the snowy layer. You could write a script that just duplicates the normal tiles and modifies their layer and background at the start of the room so it's less manual labor for you.

if snowing {
tile_layer_hide(spring_layer)
tile_layer_show(snow_layer)
}


Edit: Oh wait, I remember what I did. Forget about the tile layers. Change the background itself. Make a dummy background and use that to build your rooms. Then assign the proper seasonal background to the dummy background.
 
Last edited:
Top