GameMaker Creating tiles in a room based on a ds_grid

S

Snayff

Guest
Afternoon all,

My end goal...
is to have an xls that holds all possible room designs, formatted in grids. Each cell in a grid contains a number which corresponds to the tile that needs to be placed. I would then "stitch" the rooms together to create one large map.

My current problem...
is with drawing the tiles to the Room. The code compiles and runs error free but nothing displays on the screen. I think it may be due to the _collisionLayer returning 0, though I am not sure why it has. That, or I am adding the tiles in the incorrect manner.

I have copied my code below. Please note that this uses placeholder values for now and the code will eventually be split out in to the discrete scripts.

Any help would be greatly appreciated!

-Snayff

Code:
///@desc use data to create room

#macro EXIT 99
#macro EMPTY 0
#macro WALL 1
#macro WATER 2
#macro BRIDGE 3
#macro CRAWLER 4

var _y = 0;
var _x = 0;
var _tileCode = 0;
roomDesign[1] = ds_grid_create(10,10);

//loop Y
for (_y = 0; _y < 10; _y += 1) {
    
    //loop X
    for (_x = 0; _x < 10; _x += 1) {
        _tileCode = 1;
        ds_grid_set(roomDesign[1], _x, _y, _tileCode);
    }
}
//var _tileCode = 0;// ref from data that dictates what tile to add
var _yCell = 0; // cell counter
var _xCell = 0; // cell counter
var _roomHeightInCells = ds_grid_height(roomDesign[1]); //how high is the room, in cells
var _roomWidthInCells = ds_grid_width(roomDesign[1]); // how wide is the room, in cells
var _collisionLayer = layer_get_id("COLLISION"); //get layer info
var _collisionTilemap = layer_tilemap_get_id(_collisionLayer); //get tilemap info
var _collisionTileData =  tilemap_get(_collisionTilemap, 2,2); //get required tile info


//loop Y
for (_yCell = 0; _yCell < _roomHeightInCells; _yCell += 1) {
    
    //loop X
    for (_xCell = 0; _xCell < _roomWidthInCells; _xCell += 1) {
        
        //take tile code from room design
        _tileCode = ds_grid_get(roomDesign[1], _xCell,_yCell);
        
        switch _tileCode {
            case WALL :
                tilemap_set(_collisionTilemap, _collisionTileData, (_xCell + 1) * TILESIZE, (_yCell + 1) * TILESIZE);
                break;
        }
        
        
    }
    
}
 
E

EggPlant <3

Guest
Keep in mind that tilemap_set uses tile grid indices, rather than the real position in the room. If you want to use real X/Y coordinates, use tilemap_set_at_pixel

EDIT:

Also I don't see where TILESIZE is being set either, but I assume that's the size of the tile in pixels?
 
Last edited by a moderator:
S

Snayff

Guest
@EggPlant <3 Thanks for coming back to me.

You're right, TILESIZE is set elsewhere and does relate to the tile size in pixels.

I tried using tilemap_set_at_pixel instead but it didnt change anything I am afraid. Still only a black screen. Any other thoughts?
 
E

EggPlant <3

Guest
The next thing I would do is stick a breakpoint by clicking on the left-hand coloumn in the code and run in debug mode (F6). Then step through the code (use F10 to step line by line) and make sure the likes of _collisionTileMap etc. are actually correctly referencing the tile layer as expected. (it will return -1 if the layer is not found). You can see the value by putting your mouse over a useage of the variable AFTER it's been declared (so step to a line after it)

upload_2018-3-24_17-47-53.png

Additionally, if you don't require the use of setting tiles by actual pixel position, then just revert to using tilemap_set and remove the tile size conversions:
Code:
tilemap_set(_collisionTilemap, _collisionTileData, (_xCell + 1) , (_yCell + 1));
 
S

Snayff

Guest
@EggPlant <3 They all return 0. I stepped through each loop but nothing comes on to the screen. I am not sure if it is the draw method or the queries for the data. It looks right, from what I know, and I have actually used some of the code elsewhere and had it working, so I am fairly perplexed!
 
Top