• 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!

GML Drawing text to a tile layer?

B

BigBrotherBear

Guest
Is it possible to draw text to a tile layer. I've been racking my brain trying to figure this one out.
 

Bart

WiseBart
The Room Editor forces you to use a specific type of asset per layer.
But in code you can use any asset type, as the manual says on layers:

"but note that unlike the room editor, you are not limited to a single asset type per layer, and can add multiple asset types to the same layer"

You want text to be drawn. That can only be done by an instance of an object.
So creating an instance that draws the text using instance_create_layer on the tile layer will probably make it work.
 
B

BigBrotherBear

Guest
I don't think I was specific, and for that I'm sorry. I want to be able to draw text to a tile layer, not an object layer.

tile_add, but instead of adding a background tile, convert what is written there to a tile layer. So that I can move it using tile_layer_shift
 

TheouAegis

Member
If the letters are already in the tileset, you need to loop through the string and add each tile to the tilemap. This will erase the tiles already at that position, though. If the text is in a separate sprite, you should just be able to loop through the string and add the sprite of each letter using layer_sprite_create().
 
B

BigBrotherBear

Guest
That is also a sprite layer, not a tile layer, or an object layer.
 

TheouAegis

Member
Did you read what Bart said? Once the game has been compiled, you can put anything on a layer. There is no such thing as an "object layer" or a "sprite layer" or a "tile layer". They're all just "layers" once the program is compiled.

Edit: As for how to get the sprite to draw on top of the tiles, I don't know about that.
 
Last edited:
B

BigBrotherBear

Guest
I did read what Bart wrote, the edit YOU wrote "draw on top of the tiles," is exactly what I am looking for.
 

TheouAegis

Member
I did read what Bart wrote, the edit YOU wrote "draw on top of the tiles," is exactly what I am looking for.
As for getting the sprite to draw over the tiles, I figured out a workaround.

var layerID = layer_get_id("the target layer")
//run your code for adding the sprite to the layer
var tilesID = layer_tilemap_get_id(layerID);
layer_element_move(tilesID, layerID+1) //or -1, depending on how your layers are set up
layer_element_move(tilesID,layerID); //this resets the ordering so the tiles should now be drawn first


The layer drawing seems to be LIFO ordering. Since the sprites will be the last thing you add, the sprites will get drawn first and then the tiles, which were the first because they were added in the IDE, will get drawn last on top of the sprites. By yanking the tilemap out of the layer after you add the sprites, then putting them back in, the tilemap becomes the last element added, so it gets drawn first.

Keep in mind if you want the text to be able to disappear as the layer changes (not sure if it's relevant to your project, but I'm just throwing this out there), you will need to store the sprite elements' IDs in a list or array so you can find them later, since layer_sprite_get_id() is only for sprites added in the IDE.
 
Last edited:
B

BigBrotherBear

Guest
I see what you're trying to do with the code above, but I don't think it'll work for what I'm trying to accomplish. I appreciate you taking the time to try to work out a solution though. The layer still does not move with tile_layer_shift, unfortunately.
 

TheouAegis

Member
I see what you're trying to do with the code above, but I don't think it'll work for what I'm trying to accomplish. I appreciate you taking the time to try to work out a solution though. The layer still does not move with tile_layer_shift, unfortunately.
tile_layer_shift()? You're using Studio 1.4? You can't add anything to a tile layer, which isn't actually even a real layer at all. They just call it a "layer", but real layers weren't added until Studio 2. You might still be able to take a background image with all the letters/numbers and add the actual tiles in the same layer without them deleting the tiles underneath (via code). If even via code they still delete the tiles underneath, then you'll need to create another layer at a lower depth.
 
B

BigBrotherBear

Guest
Right, so the draw_text_ext draws them proportionally, and that's how I need them to be; but converted from the text drawn to tiles. Does that make sense?
 

TheouAegis

Member
Yes it makes sense. You would need to draw the text to a surface. If you want to insist on them being tiles, you would then need to save the as a background, then add the background as a tile. If the surface is going to contain multiple "tiles" of different sizes, you would also need to store the dimensions of each tile (left, top, width, height) in an array so you can then pick and choose which tiles you want to add to the room in case multiples of the same tile will be used. This is not something that GMS1.4 handles easily.
 
Top