Author Topic: SOLVED: Line drawing not drawing past a certain point on the screen.  (Read 334 times)  Share 

Uhfgood

  • No pain, no game!
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: Adventure Game Studio
  1. // main global script file
  2. DynamicSprite *screen_sprite;
  3. int startx = 0;
  4. int starty = 0;
  5.  
  6. function draw_line_on_screen(int from_x,  int from_y,  int to_x,  int to_y,  int r,  int g,  int b)
  7. {
  8.         DrawingSurface *surface = screen_sprite.GetDrawingSurface();
  9.         surface.Clear();
  10.         surface.DrawingColor = Game.GetColorFromRGB(r,  g,  b);
  11.         surface.DrawLine(from_x,  from_y,  to_x,  to_y);
  12.         surface.Release();
  13.         gScreenGUI.BackgroundGraphic = screen_sprite.Graphic;
  14. }
  15.  
  16. function clear_screen()
  17. {
  18.         DrawingSurface *surface = screen_sprite.GetDrawingSurface();
  19.         surface.Clear();
  20.         surface.Release();
  21.         gScreenGUI.BackgroundGraphic = screen_sprite.Graphic;
  22. }
  23.  
  24. // called when the game starts, before the first room is loaded
  25. function game_start()
  26. {
  27.         screen_sprite = DynamicSprite.Create(System.ViewportWidth,  System.ViewportHeight);
  28. }
  29.  
  30. // put anything you want to happen every game cycle in here
  31. function repeatedly_execute()
  32. {
  33.         if( gPieMain01.Visible == true )
  34.                 draw_line_on_screen(startx,  starty,  mouse.x,  mouse.y,  192,  0,  0);
  35.         else
  36.                 clear_screen();
  37. }
  38.  
  39. // put here anything you want to happen every game cycle, even when the game is blocked
  40. function repeatedly_execute_always()
  41. {
  42. }
  43.  
  44. // called when a key is pressed. keycode holds the key's ASCII code
  45. function on_key_press(eKeyCode keycode)
  46. {
  47.   if (IsGamePaused()) keycode = 0; // game paused, so don't react to keypresses
  48.  
  49.   if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
  50.   if (keycode == eKeyF9) RestartGame(); // F9
  51.   if (keycode == eKeyF12) SaveScreenShot("scrnshot.pcx");  // F12
  52.   if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
  53.   if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
  54.   if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
  55.   if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
  56. }
  57.  
  58. function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  59. {      
  60.         if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
  61.         {
  62.         }
  63.         else if (button == eMouseLeft)
  64.         {
  65.                 if( gPieMain01.Visible == false )
  66.                 {
  67.                         gPieMain01.SetPosition( mouse.x - (gPieMain01.Width / 2),  mouse.y - (gPieMain01.Height / 2) );
  68.                        
  69.                         //if( gPieMain01.Y < 60 ) gPieMain01.Y = 60;
  70.                         //if( (gPieMain01.Y + gPieMain01.Height) > 420 ) gPieMain01.Y = 420 - gPieMain01.Height;
  71.  
  72.                         gPieMain01.Visible = true;
  73.                         startx = mouse.x;
  74.                         starty = mouse.y;
  75.                 }
  76.                 else
  77.                 {
  78.                         if( mouse.x > (gPieMain01.X + 54) && mouse.x < ( (gPieMain01.X + gPieMain01.Width) - 54) )
  79.                         {
  80.                                 if( mouse.y > (gPieMain01.Y + 54) && mouse.y < ( (gPieMain01.Y + gPieMain01.Height) - 54) )
  81.                                 {
  82.                                         gPieMain01.Visible = false;
  83.                                 }
  84.                         }
  85.                 }
  86.         }
  87.         else if (button == eMouseRight) // right-click, so cycle cursor
  88.         {  
  89.                 //mouse.SelectNextMode();
  90.                 ProcessClick(mouse.x,mouse.y, mouse.Mode);
  91.         }
  92.  
  93. }
  94.  
  95.  
  96. function dialog_request(int param) {
  97. }

Ideas on why the line is cutting off?
« Last Edit: 06 Jul 2012, 22:10 by Uhfgood »

monkey_05_06

  • AGS Project Admins
  • #1 Straight Basher
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?
By and large I didn't accomplish what I set out to do, but I did accomplish a fair bit. So, there is that.

Uhfgood

  • No pain, no game!
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.

monkey_05_06

  • AGS Project Admins
  • #1 Straight Basher
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: Adventure Game Studio
  1. // GlobalScript.asc
  2.  
  3. function on_event(EventType event, int data)
  4. {
  5.   if ((event == eEventEnterRoomBeforeFadein) && (screen_sprite == null)) screen_sprite = DynamicSprite.Create(System.ViewportWidth, System.ViewportHeight);
  6. }

You should remove the line from game_start if using this.
By and large I didn't accomplish what I set out to do, but I did accomplish a fair bit. So, there is that.

Uhfgood

  • No pain, no game!
Interesting thing here.  I changed the line -
Code: Adventure Game Studio
  1. screen_sprite = DynamicSprite.Create(System.ViewportWidth,  System.ViewportHeight);
to
Code: Adventure Game Studio
  1. 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.

monkey_05_06

  • AGS Project Admins
  • #1 Straight Basher
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.
By and large I didn't accomplish what I set out to do, but I did accomplish a fair bit. So, there is that.

Ghost

  • Guest
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.