• 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!

Legacy GM [SOLVED]Sprites are being drawn behind my room.

A

ASpaceWorm

Guest
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:

Code:
// 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:

Code:
// 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:

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

{ with(player_1) { water_check(water_drops[i]); } }
water_check(water_drop):
Code:
// 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); }
The Player objects look like this:

Code:
///init_player(playerNum)

playerNumber = argument0
level = 1;
water = 10;

drink = 50;
adj_drink = 25;
water_max = 25;

roots[0] = 0;

if(playerNumber == 1)
{
    waterPos = 10;
}
else
{
    waterPos = 600;
}
water_drops[0] = instance_create(waterPos,10,water_drop);
So, just running the game, I get a gray(bg color of the room) window when there should be a sprite 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. I have tried calling the script that is called in the game_manager step event in the draw event instead, but this results in the sprite not being drawn at all, including behind the background.

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

TheouAegis

Member
tile_add should only affect sprites if the tile is being added to a depth that is equal to or lower than the depth of the Sprite being drawn. I mean, you could try setting your tiles to be created at a depth of 10000.

is the Sprite being drawn to the left or to the right or above or below the room/View? I would assume it is not being drawn below because your coordinates suggest your drying the water at the top of the screen. Did you verify that waterpos is correct? If you are using a view, the coordinates you provided we're all to the room, not to the view.
 
A

ASpaceWorm

Guest
It is being drawn at the top-left of the window. However, I can only see it when I stretch the window so I have black bars on either side of the room. The game starts with a window the size of the room that has a gray background. At this point, I am not seeing the sprite being drawn. If I stretch the window left, I then can see the sprite at the top left of the window inside the black bar. If I stretch further, it stays in the top left, so it seems it is being drawn at position (10,10) of the window, but will not draw on top of the room's background for some reason.
 
A

ASpaceWorm

Guest
I solved this, and it was a dumb combination of dumb mistakes: my game_manager object was not set to visible(I didn't think it needed to be as just a manager object) and I was calling my draw script inside step instead of the draw event.
 
Top