A Random Creator
Member
Hello everyone! I have a relatively simple issue. I'm currently creating a rts style game, and I have a "Fog of War" which is stored in a grid. It works fine currently, however I'm having a major issue with the lag. Drawing the fog on screen is pretty simple, I just have to draw the few squares of the grid that the player can currently see, but my problem is the minimap. The minimap is drawing the entire fog grid over the map sprite, which drops the game about 60 frames lower on my pc (Originally it was running at around 100). When I disable the fog the performance gets significantly better, so I know this is the issue. My current method for drawing it is simple, I just use a for loop to draw every square over the minimap, but I feel like there's got to be a better more performance forgiving way to do this?
Here's my current code if needed:
Please excuse my sloppy code
I've thought about skipping tiles, as in drawing one square for every four squares, because the minimap is small enough to where each tile would not be noticed. However, I wasn't sure if that would be the best method, or even how I should go about programming that. Any help is appreciated, thanks in advance!
Here's my current code if needed:
Please excuse my sloppy code
Code:
if(sprite_exists(Island_Sprite)) {
var Draw_MapX = Width-GUI_MinimapScale;
var Draw_MapY = YY+2
draw_set_alpha(1)
draw_sprite_stretched(Island_WaterSprite,0,Draw_MapX,Draw_MapY,GUI_MinimapScale,GUI_MinimapScale)
draw_sprite_stretched(Island_Sprite,0,Draw_MapX,Draw_MapY,GUI_MinimapScale,GUI_MinimapScale)
var Tx = 0
var Ty = 0
var TileScale = GUI_MinimapScale/ds_grid_width(Player_FogOfWar)
var TileScaleV = GUI_MinimapScale/ds_grid_height(Player_FogOfWar)
draw_set_color(c_black)
var alph = 1
var PrevAlph = 0
for(var i=0;i<ds_grid_width(Player_FogOfWar)*ds_grid_height(Player_FogOfWar);i+=1) {
if(ds_grid_get(Player_FogOfWar,Tx,Ty) != undefined) { alph = 1-ds_grid_get(Player_FogOfWar,Tx,Ty) }
if(alph != 0) {
if(alph != PrevAlph) { draw_set_alpha(alph) PrevAlph = alph }
draw_rectangle(Draw_MapX+TileScale*Tx,Draw_MapY+TileScaleV*Ty,Draw_MapX+TileScale*Tx-1,Draw_MapY+TileScaleV*Ty-1,0)
}
Tx += 1 if(Tx >= ds_grid_width(Player_FogOfWar)) { Tx = 0 Ty += 1}
}