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

GameMaker Tiling Rectangles

Pretty simple question, which I don't believe has a simple answer: How can I set tiles (using GML) in a given rectangle shape?
Something like tilemap_set:

tilemap_set_rectangle(tilemap_element_id,tiledata,cell_x1,cell_y1,cell_x2,cell_y2)

I feel like something like this would be rather useful.
 

rIKmAN

Member
There is no built in function to do this, but you already have the starting cell x/y, the end cell x/y and you should know the size of the tiles which means you can just use a a couple of for loops to iterate over those cells and use the regular tile function of your choice to change each tile as you loop through them.

Ideally write a script that takes all the data as arguments so you can pass in the layer, tilemap, start cell x/y, end cell x/y, tile id used to fill the rectangle etc etc so that it can be reused by calling the script anywhere in your project with the required arguments.
 
Last edited:
Thank you! I just seem to get stuck sometimes, and I completely forgot loops existed for.. some reason. Actually, I thought I would have to do some weird var i++ stuff to solve this.

Anyway, I whipped something up that fixes my problem if anyone needs it:

Code:
// tilemap_set_rectangle(tilemap_element_id, tiledata, cell_x1, cell_y1, cell_x2, cell_y2)
/// @desc tilemap_set_rectangle(tilemap_element_id,tiledata,cell_x1,cell_y1,cell_x2,cell_y2)
/// @param tilemap_element_id
/// @param tiledata
/// @param cell_x1
/// @param cell_y1
/// @param cell_x2
/// @param cell_y2

var rex = abs(argument4 - argument2);
var rey = abs(argument5 - argument3);

var celx = argument2;
var cely = argument3;

var mox = sign(argument4 - argument2);
var moy = sign(argument5 - argument3);


repeat ((rey+1)*(rex+1)) {
    tilemap_set(argument0,argument1,celx,cely)
    celx = celx + mox
    if celx == (argument4 + mox) then {
        celx = argument2
        cely = cely + moy
    }
};
 
Top