Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Uhfgood on Wed 04/07/2012 21:02:12

Title: SOLVED: Trying to draw a line on the screen.
Post by: Uhfgood on Wed 04/07/2012 21:02:12
I'm trying to draw a line over everything, using a drawing surface and an overlay (and dynamic sprite).

Code (AGS) Select
// main global script file
DynamicSprite *screen_sprite;

// called when the game starts, before the first room is loaded
function game_start()
{
screen_sprite = DynamicSprite.Create(System.ViewportWidth,  System.ViewportHeight);
}

function draw_line_on_screen(int from_x,  int from_y,  int to_x,  int to_y,  int r,  int g,  int b)
{
DrawingSurface *surface = screen_sprite.GetDrawingSurface();
surface.DrawingColor = Game.GetColorFromRGB(r,  g,  b);
surface.DrawLine(from_x,  from_y,  to_x,  to_y);
surface.Release();
Overlay *myOverlay = Overlay.CreateGraphical(0,  0, screen_sprite.Graphic,  true);
}

Usage: (at the bottom of the function)

Code (AGS) Select
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
{
}
else if (button == eMouseLeft)
{
  if( gPieMain01.Visible == false )
  {
  gPieMain01.SetPosition( mouse.x - (gPieMain01.Width / 2),  mouse.y - (gPieMain01.Height / 2) );
  gPieMain01.Visible = true;
  }
  else
  {
  if( mouse.x > (gPieMain01.X + 134) && mouse.x < ( (gPieMain01.X + gPieMain01.Width) - 134) )
  {
  if( mouse.y > (gPieMain01.Y + 91) && mouse.y < ( (gPieMain01.Y + gPieMain01.Height) - 61) )
  {
  gPieMain01.Visible = false;
  }
  }
  }
}
else if (button == eMouseRight) // right-click, so cycle cursor
{   
//mouse.SelectNextMode();
ProcessClick(mouse.x,mouse.y, mouse.Mode);
}

draw_line_on_screen(50,  50,  100,  100,  255,  255,  255);

}


Could anyone tell me what i'm doing wrong? Thanks!
Title: Re: Trying to draw a line on the screen.
Post by: Khris on Wed 04/07/2012 22:52:45
Just like the DynamicSprite, define the Overlay outside any function. Otherwise it is a local variable and gets destroyed at its end.
Title: Re: Trying to draw a line on the screen.
Post by: Uhfgood on Thu 05/07/2012 05:06:03
That works thanks.

Now i need to know if there's a way to make sure the line draws on top of everything including the guis.  I read in some other thread that it wasn't possible.  Kind of makes what I'm trying to do tough.  My gui uses a radial menu and not regular buttons.  So I need to show feedback to the player as to where he's dragging the mouse.
Title: Re: Trying to draw a line on the screen.
Post by: Uhfgood on Thu 05/07/2012 06:34:38
Figured it out guys.  Create a new GUI, set the z-order to the highest number possible (I think it's 1000).  Make the gui transparent, cover the screen, initially on, and NOT CLICKABLE.

Next you can create dynamic sprites, grab a surface, draw, and set the gui to the dynamic sprite's .Graphic property.

This is how you draw over the entire screen including the GUI's :-)