• 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 How can I draw tiles with selected depth with code?

BMatjasic

Member
Hello guys, I've been working on a level editor for my game and i've been wondering, how can you add tilesets layered with certain depth. I've tried the following, but it didn't seem to work...:

HTML:
if(mouse_check_button(mb_left) and keyboard_check(vk_shift)  and !point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0),x,y,x+sprite_get_width(spr_obj_selector), y+sprite_get_height(spr_obj_selector))) {
   
    if(mouse_x < room_width and mouse_y < room_height) {
    layer_force_draw_depth(false,selected_depth );
    tilemap_set_at_pixel(selected_tilemap, global.selected_tile, mouse_x, mouse_y);
    }
}
Thanks in advance!
 

rIKmAN

Member
Hello guys, I've been working on a level editor for my game and i've been wondering, how can you add tilesets layered with certain depth. I've tried the following, but it didn't seem to work...:

HTML:
if(mouse_check_button(mb_left) and keyboard_check(vk_shift)  and !point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0),x,y,x+sprite_get_width(spr_obj_selector), y+sprite_get_height(spr_obj_selector))) {
 
    if(mouse_x < room_width and mouse_y < room_height) {
    layer_force_draw_depth(false,selected_depth );
    tilemap_set_at_pixel(selected_tilemap, global.selected_tile, mouse_x, mouse_y);
    }
}
Thanks in advance!
Are you talking about individual tiles or tile layers?

If it's the latter you can set the layer depth of the tile layer using layer_depth, but you can't set individual tiles on a tile layer to be a different depth from each other - you need to use multiple layers.

You could write a system for your editor which allowed setting a per tile depth on the front end, but which just placed them on different layers on the back end.
 

BMatjasic

Member
I'm using 3 different layers ground_layer, mid_layer and top layer for tilesets. How could I change the layer for tilemap? Is this perhaps possible?
 

rIKmAN

Member
I'm using 3 different layers ground_layer, mid_layer and top layer for tilesets. How could I change the layer for tilemap? Is this perhaps possible?
As I said above, use layer_depth() to set the depth of each of your tile map layers...
 

BMatjasic

Member
layer_depth will globally change the whole layer and therefore that will bring other tiles in the same layers above the surface...
 

rIKmAN

Member
layer_depth will globally change the whole layer and therefore that will bring other tiles in the same layers above the surface...
Then put the tiles on different layers.

As I said above, there is currently no way to set tiles on the same layer to have a different depth, but you could write a system in your editor that faked this by allowing you to set depth for each tile, but behind the scenes was actually adding them to separate layers.

If the editor is only for your use (and not to be shipped for players to use) you may as well just use separate layers to start with rather than write a system to fake it.
 

BMatjasic

Member
Okay, so I did the following. I've created 3 Different layers with 3 different depths. I'm using the following code to check whether currently, that layer is selected:

Code:
var lay = "Ground";
switch(selected_depth) {
   
    case 0:
    lay = "Ground";
   
    break;
   
    case 1:
    lay = "Medium";
    break;
   
    case 2:
    lay = "Top";
    break;
}

var l = layer_get_id(lay);

var l2 = layer_tilemap_create(lay,0,0,tiles_grass, room_width, room_height);

tilemap_set_at_pixel(l2, global.selected_tile, mouse_x, mouse_y);
But it seems I'm getting the following error in debugger:

layer_tilemap_create() - could not find specified layer in current room
tilemap_set_at_pixel() - couldn't find specified tilemap


Thank you very much for taking your time!
 
Top