Moving tiles drawn in code onto the appropriate layer

A

atmobeat

Guest
Greetings, I'm working on an old top-down game that used objects instead of tiles for floors and walls, and I want my floors and walls to be tiles for the added speed. The game's spells are supposed to be able to change walls and floors into other walls and floors (e.g. my freeze spell changes a regular floor tile into a frozen tile, and my melt spell changes a wall into a lava floor tile, etc.). I know how to get my spells to detect what kind of tile in the tilemap the spell is interacting with.

Correct me if I'm wrong but it seems that if I draw a tile where a tile used to be, the old tile is replaced and goes away (as long as they're on the same layer, right?). So if I draw my frozen tile where my regular floor tile used to be, then the floor tile will go away, right? I assume it works this way because there doesn't seem to be a delete tile function and I think I saw someone mention this in some other random thread. My problem is that when you use the draw_tile function the tile is drawn on the same layer as the instance executing the draw_tile function. That isn't good for my top-down game as I'm using MirthCastle's layer sorting technique, so if my spell_freeze object draws a frozen tile it will be on the wrong layer, and my characters will be drawn under the frozen floor tile. I can't find a function for changing what layer a tile is on. Does one exist?

If not, I've been able to think of a workaround. The idea is to change the layer that the instance using draw_tile is on using layer_add_instance, then draw the tile from the spell object, and then change the spell's layer back to its original layer. Is there a better way to dynamically change tiles into other tiles and keep them on/move them onto the correct layer?
 
A

atmobeat

Guest
I did find layer_element_move but do tiles have an element ID? I don't think they do. I think tilemaps are elements but not tiles. I'm so confused.
 

Simon Gust

Member
Individual tiles all have an id. But in GMS 2 you can only get it by finding with position.
In GMS 1.4 you could just call tile_get_ids and it would return an array with all the tile ids.

Look at tilemap_get_at_pixel()

I don't know if tiles are considered elements though, probably not.
 
A

atmobeat

Guest
Individual tiles all have an id. But in GMS 2 you can only get it by finding with position.
In GMS 1.4 you could just call tile_get_ids and it would return an array with all the tile ids.

Look at tilemap_get_at_pixel()

I don't know if tiles are considered elements though, probably not.
Yes, that's one of the functions I use to detect which tile it is in the tilemap and use game logic to determine what tile to draw using draw_tile, but how does that help me get the newly drawn tile onto the appropriate tile layer? The blob of data returned does not include anything about layers. The page for the draw_tile function says that the drawn tile is put on the same layer as the instance calling the function. I think the only way around this is to move the instance, I just would like some confirmation from someone who knows more than I that there is no function for moving tiles between layers.
 

Simon Gust

Member
I read it as if you use draw_tile, you are drawing the tile manually but you are not adding it to any tilemap, you're drawing it to the commanding instance's layer. So that definetly isn't the solution.

What you want is to exchange a tile with another while it stays on the tilemap or tilelayer or whatever they use.
I saw that with tile_set_index you could choose another index for the tilelayer, but the image has to be in the same tileset.
This is also not practical I guess.

There is a function to set a tile (tilemap_set_at_pixel)
but I doubt it allows you to choose from another tileset.
As from layer_tilemap_create(), it has an argument to set the tileset, which leads me to believe, each tilemap can only have one tileset.
 
A

atmobeat

Guest
First, thanks for being the only person on here trying to help me out.

I read it as if you use draw_tile, you are drawing the tile manually but you are not adding it to any tilemap, you're drawing it to the commanding instance's layer. So that definetly isn't the solution.
The tile is already in a tilemap on the layer "Floors" or "Walls" so I don't need to add it to one. Using draw_tile isn't a solution by itself, but if you first move the instance to the appropriate layer using layer_add_instance and then use draw_tile. The tile will be on the correct layer. I think this is the only way to do it (assuming the drawn tile also replaces any tile that is currently on that layer and at that location in the room).

What you want is to exchange a tile with another while it stays on the tilemap or tilelayer or whatever they use. I saw that with tile_set_index you could choose another index for the tilelayer, but the image has to be in the same tileset. This is also not practical I guess.
Yes, exchange them in the room on the same tilelayer, not tilemap. Tile_set_index can be used along with tilemap_set to change the index, or position, of the tile within the tilemap (a tilemap is just a tileset assigned to a layer). I don't want to manipulate my tilemaps. That might also have unforeseen consequences since that data is used to draw all the floor/wall tiles (I might mix up a bunch of tiles or something).

There is a function to set a tile (tilemap_set_at_pixel)
but I doubt it allows you to choose from another tileset. As from layer_tilemap_create(), it has an argument to set the tileset, which leads me to believe, each tilemap can only have one tileset.
Maybe I'm not understanding you but I just don't see the relevance here. Yes, each tilemap only has one tileset since a tilemap just IS the tileset added to a layer. The function tilemap_set_at_pixel just changes a tile within a tilemap based on the tile data at a given point in a room. Again, I don't think I want to manipulate my tilemap at all. I want my tilemap containing all my floor tiles and the one containing all my wall tiles to stay as they are. I want to manipulate the tiles that are drawn in the room. Ignoring flipping, rotating, and mirroring, the only way I see to do that is to use draw_tile.

It looks like I'm going to have to write a script that get's the correct layer from the existing tile, moves the instance calling draw_tile, then let that instance draw the tile, and finally move the instance back to its normal layer. Not super difficult but I thought maybe I was reinventing the wheel here.
 
A

atmobeat

Guest
I think what I may do now is use objects for ice, lava, and other interactable floor squares, and I'll just create instances of these objects over the floor tiles. I may try this for walls as well. Hopefully I don't get too many instances and bog my game down.

Any advice out there? If you had a game and wanted the floor and wall tiles to be things you can interact with (ice makes characters slide and lava does damage) and you also want to be able to change them from one kind to another, would you just use objects or can it be done reasonably with tiles? I would just go for it but this seems like a pretty important decision because it won't be easy to go back to tiles if the objects are too slow, and it doesn't seem easy to go back to objects if tiles aren't flexible enough.
 
Top