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

GML [3D] Drawing depth dilemma

M

MegaJim73

Guest
I have a bit of a delicate dilemma involving the drawing of depth in 3D. I have a boss object and a parent gun object, with depths of -10 and -100 respectively. One of the gun objects is a sniper rifle which draws a scope overlay when zoomed in. The boss object has a health bar drawn on the HUD when he becomes alerted. The problem here is that the scope overlay obscures the health bar due to the differences in depth. I tried setting the boss object's depth to -101 which solves this but then the boss will become invisible in the game world, hence the dilemma. Is there a way to basically draw the health bar over the scope overlay without affecting the drawing of the boss in the game world?

In the enemy object's draw event (where the enemy sprite and health bar is drawn):
Code:
{
  //code for drawing the boss in the 3D game world
  if (point_distance(x,y,global.camx,global.camy) > 240) exit;
  var tex;
  tex = sprite_get_texture(sprite,image_index);
  d3d_draw_wall(x-8*global.camsin,y-8*global.camcos,z1,
                x+8*global.camsin,y+8*global.camcos,1,tex,1,1);
  //code for drawing the boss's health bar on the hud when alerted
  if (boss_alert==1)
    {
    d3d_set_projection_ortho(0,0,640,480,0);
    d3d_set_depth(-101); //doesn't work; can't draw this over the scope overlay
    d3d_set_hidden(false);
   draw_sprite_stretched(spr_bossmugs,0,32,32,32,32);
    draw_healthbar(64,32,608,64,(mhealth/max_health)*100,c_black,c_maroon,c_red,0,1,1);
    d3d_set_hidden(true);
    }
}
In the gun object (where the HUD is chiefly drawn):
Code:
{
  d3d_set_projection_ortho(0,0,640,480,0);
  d3d_set_hidden(false);
  if (global.third==0)
  {
      if (global.scope==1)
  {
      draw_sprite_stretched(spr_snpr,0,0,0,640,400); //draws the scope overlay; this blocks the boss health bar since the depth is lower
  }
  else
  {
      draw_sprite_stretched(sprite_index,-1,160,80,320,320);
  };
  }
  draw_sprite_stretched(spr_hud,image_index,0,400,640,80);
  if (health<102)
  {
      draw_sprite_stretched(ico_face,floor(abs(health-100)/20),4*2,410,29*2,30*2);
  }
  else
  {
      draw_sprite_stretched(ico_face,0,4*2,410,29*2,30*2);
  };
  draw_set_halign(fa_center);
  draw_text_color(320,8,global.message,c_red,c_red,c_red,c_red,0.9);
  draw_text_color(320,32,global.message2,c_red,c_red,c_red,c_red,0.9);
  draw_set_halign(fa_left);
  draw_text(43*2,448,health);
  switch (global.current_weapon)
  {
      case 4: draw_text(145*2,448,global.rounds); break;
      case 5: draw_text(145*2,448,global.rounds); break;
      case 6: draw_text(145*2,448,global.fuel); break;
      case 7: draw_text(145*2,448,global.rockets); break;
      default: draw_text(145*2,448,global.ammo);
  }
  draw_text(190*2,448,global.totalsecrets);
  draw_text(230*2,448,score);
  draw_text(282*2,448,global.totaltime);
  draw_sprite_stretched_ext(spr_wall1,0,0,0,640,400,c_red,(1-(health/50))-0.5);
  draw_sprite_stretched(spr_floor_pst,global.current_weapon,74*2,408,120,60);
  if (global.havegoldkey=true)
  {
      draw_sprite_stretched(ico_keys,0,173*2,408,16,32);
  };
  if (global.havesilverkey=true)
  {
      draw_sprite_stretched(ico_keys,1,173*2,440,16,32);
  };
  draw_set_alpha(1);
  d3d_set_hidden(true);
}
 
M

Misu

Guest
I dunno why your boss object becomes invisible (seems weird) but I can tell you that if you are using GMS 1.4 then you could also use Draw GUI event which works like a substitute for d3d_set_projection_ortho. Another tip is that you could try to use a single object that can perform the ortho display for all the other objects instead.
 
M

MegaJim73

Guest
Took your advice and created a separate boss HUD object. After a few tweaks, it finally works. I didn't want to create too many unnecessary objects but can't let the existing ones do everything. Thanks anyway.
 
Top