• 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 how to move all tiles with different depths in the room using code

Z

Zanget

Guest
regards! I want to move 80 pixels in the x position of each tile, I have done some quick tests and it does not work correctly.
this is what i have for now:

for (var i = 0; i < 1000; i++){
var tile;
tile = tile_layer_find(100000, i, i);
xx = tile_get_x(tile);
yy = tile_get_y(tile);
tile_set_position(tile, xx + 80, yy);
}

1605122339596.png
 

Simon Gust

Member
Make sure to read up on the manual for each function by clicking with the mouse wheel on the function.
The manual states, that tile_layer_find takes x and y, not index.

That said, instead of using tile_layer_find, you should use tile_get_ids_at_depth() which returns an array filled with all tiles at given depth.
Code:
var tiles = tile_get_ids_at_depth(100000);
var len = array_length_1d(tiles);
for (var i = 0; i < len; i++)
{
    var tile = tiles[i];
    tile_set_position(tile, tile_get_x(tile) + 80, tile_get_y(tile));
}
or if you want to do it very shortly
Code:
tile_layer_shift(100000, 80, 0);
These methods will only shift the tiles while the game is running and if the room isn't persistent (I believe) the tiles will be reset to their original position.

If you want to shift the tile layer in the room, you can press this button
1605126352611.png
 
Z

Zanget

Guest
Make sure to read up on the manual for each function by clicking with the mouse wheel on the function.
The manual states, that tile_layer_find takes x and y, not index.

That said, instead of using tile_layer_find, you should use tile_get_ids_at_depth() which returns an array filled with all tiles at given depth.
Code:
var tiles = tile_get_ids_at_depth(100000);
var len = array_length_1d(tiles);
for (var i = 0; i < len; i++)
{
    var tile = tiles[i];
    tile_set_position(tile, tile_get_x(tile) + 80, tile_get_y(tile));
}
or if you want to do it very shortly
Code:
tile_layer_shift(100000, 80, 0);
These methods will only shift the tiles while the game is running and if the room isn't persistent (I believe) the tiles will be reset to their original position.

If you want to shift the tile layer in the room, you can press this button
View attachment 35640
I had no idea 😅😅 !! Thank you very much you saved me from a long work moving each tile
 
Top