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:
Inside generateMap(), we have:
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:
water_check(water_drop):
The Player objects look like this:
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!
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();
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);
}
}
}
*/
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]); } }
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); }
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);
Any help is appreciated, as this is a really frustrating problem that I just cannot figure out. Thanks!