r/gamemaker•
ASpaceWorm

[Help]GM 1.4: Sprites are being drawn behind my room.

Help!

I'm still very new to GML and am learning, but I've run into this very weird issue. I don't have much of anything going on yet, but I have a room that's empty except for a game_manager object. On create, it runs this script:

// Initialize both players and the map

player_turn = 1;

player_1 = instance_create(0,0,player);

player_turn = 2;
player_2 = instance_create(0,0,player);

generateMap();

Inside generateMap(), we have:

// Create the initial map based on input grid

mapGrid = ds_grid_create(1,0);

if(file_exists("testMap.txt"))
{
    file = file_text_open_read("testMap.txt");
    while(!file_text_eof(file))
    {
        ds_grid_resize(mapGrid, ds_grid_width(mapGrid), ds_grid_height(mapGrid) +1);        
    
        line = file_text_readln(file);
    if(string_length(line) - 1 > ds_grid_width(mapGrid))
    {
            ds_grid_resize(mapGrid, string_length(line), ds_grid_height(mapGrid));
    }
    
    for(var i = 1; i < string_length(line); i++)
    {
        currChar = string_char_at(line, i);
        if(string_ord_at(line, i) > 30)
        {
            mapGrid[# i, ds_grid_height(mapGrid) - 1] = string_char_at(line, i);
        }
    }
}
file_text_close(file);
}

height = ds_grid_height(mapGrid);
width = ds_grid_width(mapGrid);

// Center the map on the screen
//mapLeft = (view_wview[0] / 2) - ((width * CELL_WIDTH) / 2);
//mapTop = (view_hview[0] / 2) - ((height * CELL_HEIGHT) / 2);

/*
for(var i = 0; i < width; i++)
{
    for(var j = 0; j < height; j++)
   {
        if(mapGrid[# i, j] == "G")
        {
            tile_add(tileset,0,0,CELL_WIDTH,CELL_HEIGHT,(CELL_WIDTH * i) + mapLeft,(CELL_HEIGHT * j) + mapTop,0);
        }
        else if(mapGrid[# i, j] == "1")
        {
            tile_add(tileset,0,32,CELL_WIDTH,CELL_HEIGHT,(CELL_WIDTH * i) + mapLeft,(CELL_HEIGHT * j) + mapTop,0);
        }
        else if(mapGrid[# i, j] == "2")
        {
            tile_add(tileset,32,32,CELL_WIDTH,CELL_HEIGHT,(CELL_WIDTH * i) + mapLeft,(CELL_HEIGHT * j) + mapTop,0);
        }
    }
}

*/

You can see I commented out a big block that was using a ds_grid to draw tiles to the screen. These were drawing to the room as intended. But my first assumption was that tile_add was interfering with sprite_draw in some way.

Then, in the game_manager step event, I do the following bits:

// Draw the water droplets
for(var i = 0; i < array_length_1d(player_1.water); i++)

{ with(player_1) { water_check(water[i]); } }

// Has the water drop check if it's empty or full and draw itself accordingly.
if(argument0.full)
{
    draw_sprite(drop_full,-1,argument0.x,argument0.y);
}

else { draw_sprite(drop_empty,-1,argument0.x,argument0.y); }

So, just running the game, I get a gray(bg color of the room) window when there should be two sprites drawn in there. If I stretch the window out so that I get black bars to the left/right, I can see the sprite that is supposed to be drawn to the room, which makes me think the sprite is being drawn to the window instead of to the room/view/whatever.

Any help is appreciated, as this is a really frustrating problem that I just cannot figure out. Thanks!

Posted Jul 16, 2017, 10:27 PM UTC

56
Loading comments…