SOLVED: Line drawing not drawing past a certain point on the screen.

Started by Uhfgood, Fri 06/07/2012 04:28:39

Previous topic - Next topic

Uhfgood

For the most part line drawing is working.  I made a gui that's non-clickable cover the whole screen (or at least I think it's doing that, the viewport width and height is 640x480).  I then built a dynamic sprite and then draw the line to it, and then I set the graphic of the gui to this dynamic sprite.

Not sure why this is, here is the problem -



Notice how the red line does not go all the way down to the cursor?

Here's the code:

Code: AGS
// main global script file
DynamicSprite *screen_sprite;
int startx = 0;
int starty = 0;

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.Clear();
	surface.DrawingColor = Game.GetColorFromRGB(r,  g,  b);
	surface.DrawLine(from_x,  from_y,  to_x,  to_y);
	surface.Release();
	gScreenGUI.BackgroundGraphic = screen_sprite.Graphic;
}

function clear_screen()
{
	DrawingSurface *surface = screen_sprite.GetDrawingSurface();
	surface.Clear();
	surface.Release();
	gScreenGUI.BackgroundGraphic = screen_sprite.Graphic;
}

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

// put anything you want to happen every game cycle in here
function repeatedly_execute() 
{
	if( gPieMain01.Visible == true )
		draw_line_on_screen(startx,  starty,  mouse.x,  mouse.y,  192,  0,  0);
	else
		clear_screen();	
}

// put here anything you want to happen every game cycle, even when the game is blocked
function repeatedly_execute_always() 
{
}

// called when a key is pressed. keycode holds the key's ASCII code
function on_key_press(eKeyCode keycode) 
{
  if (IsGamePaused()) keycode = 0; // game paused, so don't react to keypresses
  
  if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
  if (keycode == eKeyF9) RestartGame(); // F9
  if (keycode == eKeyF12) SaveScreenShot("scrnshot.pcx");  // F12
  if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
  if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
}

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) );
			
			//if( gPieMain01.Y < 60 ) gPieMain01.Y = 60;
			//if( (gPieMain01.Y + gPieMain01.Height) > 420 ) gPieMain01.Y = 420 - gPieMain01.Height;

			gPieMain01.Visible = true;
			startx = mouse.x;
			starty = mouse.y;
		}
		else
		{
			if( mouse.x > (gPieMain01.X + 54) && mouse.x < ( (gPieMain01.X + gPieMain01.Width) - 54) )
			{
				if( mouse.y > (gPieMain01.Y + 54) && mouse.y < ( (gPieMain01.Y + gPieMain01.Height) - 54) )
				{
					gPieMain01.Visible = false;
				}
			}
		}
	}
	else if (button == eMouseRight) // right-click, so cycle cursor
	{   
		//mouse.SelectNextMode();
		ProcessClick(mouse.x,mouse.y, mouse.Mode);
	}

}


function dialog_request(int param) {
}


Ideas on why the line is cutting off?

monkey0506

You said you "think" that the GUI is covering the whole screen...so just to be perfectly clear, what are the X, Y, Width, and Height of your gScreenGUI set to?

Uhfgood

Left, 0, Top 0, Width 640, Height 480

After inspecting the actual height of the dynamic sprite, it's only showing 400 for some reason.  Whereas the height I created it with which was the viewport is still showing 480.

monkey0506

System.ViewportWidth and System.ViewportHeight aren't reliable for use until the first room has been loaded (first load or before fade-in is fine). I'm not sure if this is documented, but the values aren't (always) correct in game_start.

Didn't catch that before. Based on only the one screenshot and limited description, hard to say if this is the only issue...but try creating it like this:

Code: ags
// GlobalScript.asc

function on_event(EventType event, int data)
{
  if ((event == eEventEnterRoomBeforeFadein) && (screen_sprite == null)) screen_sprite = DynamicSprite.Create(System.ViewportWidth, System.ViewportHeight);
}


You should remove the line from game_start if using this.

Uhfgood

Interesting thing here.  I changed the line -
Code: AGS
screen_sprite = DynamicSprite.Create(System.ViewportWidth,  System.ViewportHeight);
to
Code: AGS
screen_sprite = DynamicSprite.Create(640, 480);
-- and it works perfectly.  For some reason at game start I guess the viewport height is set to 400 for some odd reason?

I see from your reply, about the viewport w/h not being reliable until the first room has been loaded.  Thanks for your help.

It's not documented, however.

monkey0506

It may be for some type of legacy reasons (not sure), but I think that in game_start it always returns a multiple of 320x200 (although the actual window itself in windowed mode is the right size).

In future versions that would be something that should be updated, but it's generally not an issue (hence it not being well documented anywhere) and is easily worked around.

Ghost

Quote from: monkey_05_06 on Fri 06/07/2012 08:35:39
but I think that in game_start it always returns a multiple of 320x200

Confirmed(?): It's also impossible to set a GUI's y position to anything over 200 in game_start, but you can set it to that once the first room has been loaded. I cried over that a couple of times already.

Seems like AGS initially uses the lowest possible resolution of 320x200.

SMF spam blocked by CleanTalk