• 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 Questions about creating and using data structures

D

dorijan5484

Guest
Hello,

I'm trying to read the map made of multiple layers and render it in the isometric perspective. I've gotten the hang of rendering one layer of the map using ds_grid and indexing the type and depth of the tile.
Unfortunately, I'm stuck trying to read multiple layers and sorting them into the grid. In my understanding, the problem lies with trying to rewrite already filled up data-structure.

I've posted the create code of the obj_render. The object used for rendering the map and player from the map drawn from tilesets. Down below you can see how the room editor looks like and what the game looks like when run.

As I wrote this post I thought the problem might be being when the draw event is being executed. Maybe if I could run the draw event before switching for statement's i variable from 0 to 1. Then maybe creating two data structures, one as a list for the layer being read and one as a grid for reading the tilemap, could be avoided.

I guess my question would be if it's possible to execute the draw event in the middle of the create event, if the double data structure is possible and what would be the best way to execute it, or if there is a third and better way to tackle this problem?

layer_1 is visible.


layer_0 is visible.


In-game view.



Code:
// Build the map! RENDERING!!

//hiding the tile layers.
layer_set_visible("btiles_1", false);
layer_set_visible("btiles_0", false);
layer_set_visible("itiles_0", false);
layer_set_visible("itiles_1", false);

//creating the data structure
global.theMap = ds_grid_create(MAP_W, MAP_H);
//global.layerMap = ds_grid_create(4, global.theMap);

//Variables used for character creation (code needs to be optimized)
roomX = 0;
roomY = 0;
tileData = global.theMap [# 0, 0];
tileIndex = 0;
tileZ = 0;
//var tileZ_multi;

//trying to read through different layers (btiles 0 and btiles 1)
for (var i = 0; i <= 1; i++)
{
    switch (i)
    {
//selecting layer 0
        case 0:
        var tileMap = layer_tilemap_get_id("btiles_0");
        obj_render.layer = layer_get_id("mlyr_0");
        break;

//selecting layer 1   
        case 1:
        var tileMap = layer_tilemap_get_id("btiles_1");
        obj_render.layer = layer_get_id("mlyr_1");
        break;
    }

//filling up the data structure
    for (var tX = 0; tX < MAP_W; tX++)
    {
        for (var tY = 0; tY < MAP_H; tY++)
        {
            var tileMapData = tilemap_get(tileMap, tX, tY);
            //Format: [Sprite, Z] (-1 will be given if there is a problem)
            var thisTile = [-1, 0];
            thisTile[TILE.SPRITE] = tileMapData;
            //Sets the height of the tile
            switch (thisTile[TILE.SPRITE])
            {
                case 0:
                thisTile[TILE.Z] = 1000// + tileZ_multi;
                break;
                
                case 1:
                thisTile[TILE.Z] = 1 //+ tileZ_multi;
                break;
                
                case 2:
                thisTile[TILE.Z] = 1 //+ tileZ_multi;
                break;
                
                case 3:
                thisTile[TILE.Z] = 60 //+ tileZ_multi;
                break;
            }
            //same this as ds_grid function
            global.theMap[# tX, tY] = thisTile;
            
            //rendering the character
            tileData = global.theMap [# tX, tY];
            roomX = TileToScreenX(tX,tY);
            roomY = TileToScreenY(tX,tY);
        
            tileIndex = tileData[TILE.SPRITE];
            
            if(tileIndex = 2)
            {
                instance_create_layer(roomX, roomY+50, "olyr_1", obj_player);
            }

        }
    }
}
 
Top