• 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 to draw tiles to tile layer?

AnotherHero

Member
Hey everybody,

I'm making a short action game and I'm using tile collision. I am trying to implement a basic building system. The actual building is fine but I need to add collision between the player and built structures. The code I attempted to use, in the building's draw event is:
Code:
draw_self();
///@desc create collision tiles
var _tile1x = x - 40;
var _tile2x = x - 24;
var _tile3x = x + 23;
var _tile4x = x + 39;
var _layerID = layer_get_id("Collision");
var _mapID = layer_tilemap_get_id(_layerID);
var _data = tilemap_get(_mapID, 0, 0);
_data = tile_set_flip(_data, true);
//Set tile 1
draw_tile(tile_collision,_data,0,_tile1x, y -16);
//Set tile 2
draw_tile(tile_collision,_data,0,_tile2x, y -16);
//Set tile 3
draw_tile(tile_collision,_data,0,_tile3x, y -16);
//Set tile 4
draw_tile(tile_collision,_data,0,_tile4x, y -16);
But that's not working. I'm trying to create a total of 4 collision tiles on the building (the bottom half of the sprite, with some room in the middle for the door).

I read the documentation on drawing tiles but it didn't make much sense to me. For example, I don't know why everyone uses tile_set_flip.

If I need to make anything clearer, I'm happy to. Or if you have any questions that might help lead to a solution I can answer! But in the meantime, thank you for your help and time.
 

TheouAegis

Member
If you're using actual tiles, you should be adding them to the tile layer, not drawing them. You can't interact with drawn tiles.
 

AnotherHero

Member
If you're using actual tiles, you should be adding them to the tile layer, not drawing them. You can't interact with drawn tiles.
This makes total sense! For those who might stumble upon this, I moved the same code to the Create event and changed every draw_tile to tilemap_set_at_pixel.

Thanks for your help!
 
Top