Jibble

Author Topic: Scrolling screen background issues  (Read 517 times)

Re: Scrolling screen background issues
« Reply #20 on: 05 Feb 2019, 21:50 »
Normal game size room is 480x270
scrolling background is 3000x3000

Re: Scrolling screen background issues
« Reply #21 on: 05 Feb 2019, 21:51 »
Current room code is this I may have missed a change or got confused in the two replies and was unsure which one to change
getting the

Failed to save room room1.crm; details below
room1.asc(16): Error (line 16): Variable 'wrapWidth' is already defined

I was confused rather to change this or not as you both spoke of it

Code: Adventure Game Studio
  1. // room script file
  2.  
  3. // Some handy variables
  4.  int centerX, centerY, wrapWidth=1, wrapHeight=1, viewportX, viewportY;
  5.  
  6. //BEFORE ROOM LOAD SCRIPTS
  7. function room_Load()
  8. {
  9.  
  10.   cEgo.Transparency=100; //Make Character invisible
  11.   Bridge_Battle=true;    //Put room in Battle mode starting
  12.  
  13.   // Just calculate some useful values:
  14.   centerX = System.ViewportWidth/2;
  15.   centerY = System.ViewportHeight/2;
  16.   int wrapWidth = Room.Width - System.ViewportWidth;
  17.   int wrapHeight = Room.Height - System.ViewportHeight;
  18. }
  19.  
  20. // Moved all the stuff to do with the battle into its own function, to keep things tidy
  21. void updateBattle()
  22. {
  23.   // TODO: Update ships and stuff
  24.  
  25.   mouse.Update(); // This makes sure we get the most up-to-date mouse coordinates
  26.   // Calculate viewport scrolling
  27.   int moveX = mouse.x - centerX;
  28.   int moveY = mouse.y - centerY;
  29.  
  30.   // Move viewport, wrapping around
  31.   viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;
  32.   viewportY = (viewportY + moveY + wrapWidth) % wrapWidth;
  33.   SetViewPort(viewportX, viewportY);
  34. }
  35.  
  36. //scripts that repeatedly fire
  37. function room_RepExec()
  38. {
  39.   // Testing script to exit game
  40.   if (IsKeyPressed(eKeyEscape)) {
  41.     QuitGame(0);
  42.   }
  43.   //End of Testing Script  
  44.  
  45.   // If Z key is pressed and mode is battle mode
  46.   if (IsKeyPressed(eKeyZ) && Bridge_Battle==true) {
  47.  
  48.     Display("Navigation mode off."); // Display message that Scrolling mode is off
  49.     mouse.Visible=true;     // Make mouse visible
  50.     gGui2.Visible=false;     // Make target sight invisible
  51.     Bridge_Battle=false;    // Turn Battle mode off and restore full screen mouse movement
  52.     Mouse.Mode=eModePointer; // Turns mouse back into pointer mode
  53.   }
  54.  
  55.   // If Z key is pressed and battle mode is off
  56.   if (IsKeyPressed(eKeyZ) && Bridge_Battle==false) {
  57.     Display("Navigation Mode on.");  //Display Message Scrolling mode is on
  58.     Bridge_Battle=true; //Turn battle mode and scrolling back on
  59.  
  60.     viewportX = GetViewportX();
  61.     viewportY = GetViewportY();
  62.  
  63.     // Turn off mouse and turn on target sight
  64.     gGui2.Visible=true;
  65.     mouse.Visible = false;
  66.     // Center the (now invisible) mouse on the screen
  67.     mouse.SetPosition(centerX, centerY);
  68.   }
  69.  
  70.   if(Bridge_Battle)
  71.     updateBattle();
  72. }
« Last Edit: 05 Feb 2019, 21:54 by jamesreg »

Re: Scrolling screen background issues
« Reply #22 on: 05 Feb 2019, 22:15 »

Failed to save room room1.crm; details below
room1.asc(16): Error (line 16): Variable 'wrapWidth' is already defined

I was confused rather to change this or not as you both spoke of it

Yes, "int" need to be removed from that place.

Re: Scrolling screen background issues
« Reply #23 on: 05 Feb 2019, 22:28 »
yippie This compiled

But still some issues:

1) Screen is scrolling BY Itself all crazy the stars are just zipping by lol
2) The GUI target cursor is at top left side of window not centered
3) The mouse is viable on screen and do not think it is staying center because i can get the top pull down menu to pop up meaning its going up there.

It would seem it does indeed follow the mouse but it never stops moving that direction you are going.

I think I know what it is correct me if I am wrong but I have the code to change battle mode and cursor mode with the z button to switch back and forth in modes. But in rep execute I do not have it defined how to set up battle mode in the first place does this look to be the problem?

Code: Adventure Game Studio
  1. // room script file
  2.  
  3. // Some handy variables
  4.  
  5. int centerX, centerY,  wrapWidth=1, wrapHeight=1, viewportX, viewportY;
  6. //BEFORE ROOM LOAD SCRIPTS
  7. function room_Load()
  8. {
  9.  
  10.   cEgo.Transparency=100; //Make Character invisible
  11.   Bridge_Battle=true;    //Put room in Battle mode starting
  12.  
  13.   // Just calculate some useful values:
  14.   centerX = System.ViewportWidth/2;
  15.   centerY = System.ViewportHeight/2;
  16.    wrapWidth = Room.Width - System.ViewportWidth;
  17.    wrapHeight = Room.Height - System.ViewportHeight;
  18. }
  19.  
  20. // Moved all the stuff to do with the battle into its own function, to keep things tidy
  21. void updateBattle()
  22. {
  23.   // TODO: Update ships and stuff
  24.  
  25.   mouse.Update(); // This makes sure we get the most up-to-date mouse coordinates
  26.   // Calculate viewport scrolling
  27.   int moveX = mouse.x - centerX;
  28.   int moveY = mouse.y - centerY;
  29.  
  30.   // Move viewport, wrapping around
  31.   viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;
  32.   viewportY = (viewportY + moveY + wrapWidth) % wrapWidth;
  33.   SetViewport(viewportX, viewportY);
  34. }
  35.  
  36. //scripts that repeatedly fire
  37. function room_RepExec()
  38. {
  39.   // Testing script to exit game
  40.   if (IsKeyPressed(eKeyEscape)) {
  41.     QuitGame(0);
  42.   }
  43.   //End of Testing Script  
  44.  
  45.   // If Z key is pressed and mode is battle mode
  46.   if (IsKeyPressed(eKeyZ) && Bridge_Battle==true) {
  47.  
  48.     Display("Navigation mode off."); // Display message that Scrolling mode is off
  49.     mouse.Visible=true;     // Make mouse visible
  50.     gGui2.Visible=false;     // Make target sight invisible
  51.     Bridge_Battle=false;    // Turn Battle mode off and restore full screen mouse movement
  52.     Mouse.Mode=eModePointer; // Turns mouse back into pointer mode
  53.   }
  54.  
  55.   // If Z key is pressed and battle mode is off
  56.   if (IsKeyPressed(eKeyZ) && Bridge_Battle==false) {
  57.     Display("Navigation Mode on.");  //Display Message Scrolling mode is on
  58.     Bridge_Battle=true; //Turn battle mode and scrolling back on
  59.  
  60.     viewportX = GetViewportX();
  61.     viewportY = GetViewportY();
  62.  
  63.     // Turn off mouse and turn on target sight
  64.     gGui2.Visible=true;
  65.     mouse.Visible = false;
  66.     gGui2.Centre();
  67.     // Center the (now invisible) mouse on the screen
  68.     mouse.SetPosition(centerX, centerY);
  69.   }
  70.  
  71.   if(Bridge_Battle)
  72.     updateBattle();
  73. }
« Last Edit: 05 Feb 2019, 23:02 by jamesreg »

Snarky

  • Global Moderator
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
Re: Scrolling screen background issues
« Reply #24 on: 05 Feb 2019, 22:57 »
yippie This compiled

Great!

But still some issues:

1) Screen is scrolling BY Itself all crazy the stars are just zipping by lol

It would seem it does indeed follow the mouse but it never stops moving that direction you are going.

Another mistake in my code. I forgot to add the line that resets the mouse position to the middle each turn. At the very end of updateBattle(), after SetViewport(viewportX, viewportY); add the line mouse.SetPosition(centerX, centerY);

Quote
2) The GUI target cursor is at top left side of window not centered
The GUI is wherever you position it. Just put it where you want.

Quote
But in rep execute I do not have it defined how to set up battle mode in the first place does this look to be the problem?
Quote
3) The mouse is visable on screen.

You're on the right track. The problem is not in Rep_Exec but in room_Load(). When we set Bridge_Battle to true we should also set all the other settings. The best thing would be to move all the code for turning it on and off into a function, e.g.:

Code: Adventure Game Studio
  1. // variables as before
  2.  
  3. void setBattleMode(bool doBattle)
  4. {
  5.   if(doBattle != Bridge_Battle) // If set to mode we're already in, ignore
  6.   {
  7.     if(doBattle)
  8.     {
  9.       Display("Navigation Mode on.");  //Display Message Scrolling mode is on
  10.  
  11.       viewportX = GetViewportX();
  12.       viewportY = GetViewportY();
  13.  
  14.       // Turn off mouse and turn on target sight
  15.       gGui2.Visible=true;
  16.       gGui2.Centre();
  17.       mouse.Visible = false;
  18.       // Center the (now invisible) mouse on the screen
  19.       mouse.SetPosition(centerX, centerY);
  20.     }
  21.     else
  22.     {
  23.       Display("Navigation mode off."); // Display message that Scrolling mode is off
  24.       mouse.Visible=true;     // Make mouse visible
  25.       gGui2.Visible=false;     // Make target sight invisible
  26.       Mouse.Mode=eModePointer; // Turns mouse back into pointer mode
  27.     }
  28.     Bridge_Battle = doBattle;
  29.   }
  30. }
  31.  
  32. function room_Load()
  33. {
  34.   cEgo.Transparency=100; //Make Character invisible
  35.  
  36.   // Just calculate some useful values:
  37.   centerX = System.ViewportWidth/2;
  38.   centerY = System.ViewportHeight/2;
  39.   wrapWidth = Room.Width - System.ViewportWidth;
  40.   wrapHeight = Room.Height - System.ViewportHeight;
  41.  
  42.   // Start in battle mode
  43.   setBattleMode(true);
  44. }
  45.  
  46. // updateBattle() as before (with previous fixes)
  47.  
  48. function room_RepExec()
  49. {
  50.   // Testing script to exit game
  51.   if (IsKeyPressed(eKeyEscape)) {
  52.     QuitGame(0);
  53.   }
  54.   //End of Testing Script  
  55.  
  56.   // If Z key is pressed, toggle battle mode
  57.   if (IsKeyPressed(eKeyZ))
  58.     setBattleMode(!Bridge_Battle);  // Toggle battle mode on/off
  59.  
  60.   if(Bridge_Battle)
  61.     updateBattle();
  62.  }
  63.  
« Last Edit: 05 Feb 2019, 23:08 by Snarky »

Re: Scrolling screen background issues
« Reply #25 on: 06 Feb 2019, 01:09 »
Good news Its working and everything seems fine and I even started using functions instead of a lot of repeated code and junk code thanks for the help.

I still have the bug where I have to use a display command and clear it when toggling between the battle mode and cursor mode.
I do not know why it is doing that.

Code: Adventure Game Studio
  1. // room script file
  2.  
  3. // Some handy variables
  4.   function Nav_Mode ()
  5. {
  6.   Bridge_Battle=true;
  7.   mouse.Visible=false;
  8.   gGui2.Visible=true;
  9.   gGui2.Centre();
  10.   cEgo.Transparency=100;
  11.  
  12.    
  13. }
  14.  
  15. function Cursor_Mode ()
  16. {
  17.   Bridge_Battle=false;
  18.   Mouse.Mode=(eModePointer);
  19.   mouse.Visible=true;
  20.   gGui2.Visible=false;
  21.   cEgo.Transparency=100;
  22.  
  23. }
  24.  
  25. int centerX, centerY,  wrapWidth=1, wrapHeight=1, viewportX, viewportY;
  26. //BEFORE ROOM LOAD SCRIPTS
  27. function room_Load()
  28. {
  29.  BattleMode=true;
  30.   Nav_Mode();
  31.  
  32.  
  33.   // Just calculate some useful values:
  34.  
  35.   centerX = System.ViewportWidth/2;
  36.   centerY = System.ViewportHeight/2;
  37.    wrapWidth = Room.Width - System.ViewportWidth;
  38.    wrapHeight = Room.Height - System.ViewportHeight;
  39.    
  40. }
  41.  
  42. // Moved all the stuff to do with the battle into its own function, to keep things tidy
  43. void updateBattle()
  44. {
  45.   // TODO: Update ships and stuff
  46.  
  47.   mouse.Update(); // This makes sure we get the most up-to-date mouse coordinates
  48.   // Calculate viewport scrolling
  49.   int moveX = mouse.x - centerX;
  50.   int moveY = mouse.y - centerY;
  51.  
  52.   // Move viewport, wrapping around
  53.   viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;
  54.   viewportY = (viewportY + moveY + wrapWidth) % wrapWidth;
  55.   SetViewport(viewportX, viewportY);
  56.   mouse.SetPosition(centerX, centerY);
  57. }
  58.  
  59. //scripts that repeatedly fire
  60. function room_RepExec()
  61. {
  62.   // Testing script to exit game
  63.   if (IsKeyPressed(eKeyEscape)) {
  64.     QuitGame(0);
  65.   }
  66.   //End of Testing Script  
  67.  
  68.   if (Bridge_Battle==true) {
  69.     Nav_Mode();
  70.   }
  71.   if (Bridge_Battle==false) {
  72.     Cursor_Mode();
  73.   }
  74.  
  75.   // If Z key is pressed and mode is battle mode
  76.   if (IsKeyPressed(eKeyZ) && Bridge_Battle==true) {
  77.       Cursor_Mode();
  78.      
  79.     Display("Navigation mode off."); // Display message that Scrolling mode is off
  80.   }
  81.  
  82.   // If Z key is pressed and battle mode is off
  83.   if (IsKeyPressed(eKeyZ) && Bridge_Battle==false) {
  84.     Nav_Mode();
  85.     Display("Navigation Mode on.");  //Display Message Scrolling mode is on
  86.    
  87.     mouse.SetPosition(centerX, centerY);
  88.   }
  89.  
  90.   if(Bridge_Battle)
  91.     updateBattle();
  92. }
  93. }
« Last Edit: 06 Feb 2019, 01:41 by jamesreg »

Re: Scrolling screen background issues
« Reply #26 on: 06 Feb 2019, 01:39 »
jamesreg, I noticed this line in your code, in function Cursor_Mode ():
Code: Adventure Game Studio
  1. MouseMode=(eModePointer);
  2.  

I think it should probably be instead:

Code: Adventure Game Studio
  1. Mouse.Mode=eModePointer;
  2.  

Re: Scrolling screen background issues
« Reply #27 on: 06 Feb 2019, 02:04 »
I fixed that already still was not the issue with why a display statement has to be made after hitting the z hotkey to toggle the battle and cursor modes on and off.  That bug has been there in my old code before you guys helped and even now after we have tidy it up and tightened it up.
I don't know whats causing it. Id rather just hit z and toggle modes without any pop up.

Snarky

  • Global Moderator
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
Re: Scrolling screen background issues
« Reply #28 on: 06 Feb 2019, 06:57 »
First, looking at your code there's one problem that jumps out: you're setting Bridge_Battle both inside the Nav_Mode() and Cursor_Mode() functions, and before/after you call them. Don't do that! If the value is set in the functions, don't change it anywhere else, but always use the functions to change it. That way you ensure that the value of Bridge_Battle always matches the other settings.

Similarly, you should be disciplined about putting everything that has to do with switching between the modes inside the Nav_Mode()/Cursor_Mode() functions. So line 87 in the code you posted should not be part of room_RepExec(), but should go in the Nav_Mode() function. (Put the Display() call before the Nav_Mode() call to avoid the cursor moving after you center it.)

These things may seem minor, but they are actually really important in the long run. Notice how in the code I posted, the room_RepExec() bit that switches between the modes is just two lines, while in yours it's 20. (BTW, lines 68-73 in your code are wrong and should be deleted. The Nav_Mode()/Cursor_Mode() functions are only for switching modes, and you shouldn't call them constantly to switch to the mode you're already in.)

why a display statement has to be made after hitting the z hotkey to toggle the battle and cursor modes on and off.  That bug has been there in my old code before you guys helped and even now after we have tidy it up and tightened it up.
I don't know whats causing it. Id rather just hit z and toggle modes without any pop up.

So you're saying that if you take out the Display() calls, it no longer works? The reason is probably that when you press Z, you hold down the key for more than one game loop, so the mode flips off and then immediately back on, off, on, off... so it's almost random what state it ends up in.

One way to fix that is to do what Cassiebsg suggested and add a Wait(1) call instead of Display(), but you could still end up flipping it multiple times. The easiest fix is to use a flag to check that you only do it once for each keypress:

Code: Adventure Game Studio
  1. bool modeWasFlipped;
  2.  
  3. function room_RepExec()
  4. {
  5.   // Testing script to exit game
  6.   if (IsKeyPressed(eKeyEscape)) {
  7.     QuitGame(0);
  8.   }
  9.   //End of Testing Script  
  10.  
  11.   if(IsKeyPressed(eKeyZ))
  12.   {
  13.     // We only switch mode if we haven't already done so during this keypress
  14.     if(modeWasFlipped == false) // another way to write this is just: if(!modeWasFlipped)
  15.     {
  16.       if(Bridge_Battle == true)  // or just: if(Bridge_Battle)
  17.         Cursor_Mode();
  18.       else
  19.         Nav_Mode();
  20.  
  21.       modeWasFlipped = true; // We've switched mode, so set the flag
  22.     }
  23.   } // End: IsKeyPressed(eKeyZ)
  24.   else // the key is released, so we reset the flag
  25.     modeWasFlipped = false;
  26.  
  27.   if(Bridge_Battle == true) // Same: if(Bridge_Battle)
  28.     updateBattle();
  29. }

Notice also how I'm using indentation to show which different lines belong inside which if-conditions. Try to be consistent about your indentation; it makes code much easier to read. (It's sort of like punctuation for English sentences: do it wrong and you'll probably still be understood, but it's just much less readable and more confusing.)

Re: Scrolling screen background issues
« Reply #29 on: 06 Feb 2019, 07:33 »
Thank you so much for this is working exactly the way I wanted.

I know that many times it is hard helping novice coders and even doing some of or in my case much of the coding yourself and think they are just getting freebies. The things that are learned and lessons are of great assistance.

More then just the specific things in this code I picked up shorter ways to do code, more cleaner and organized ways to do it and a few commands and functions I did not think I would be able to learn and tearing though this code and examining it will help me to improve and understand further.

I greatly thank you for the assistance and your time has not been wasted on me.

Snarky

  • Global Moderator
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
Re: Scrolling screen background issues
« Reply #30 on: 06 Feb 2019, 08:33 »
Great, I'm glad it's been of use, and look forward to the game. Hope you manage to sort out the rest of it, too.

Re: Scrolling screen background issues
« Reply #31 on: 06 Feb 2019, 23:05 »
Ignore this post made a mistake
« Last Edit: 06 Feb 2019, 23:07 by jamesreg »

Re: Scrolling screen background issues
« Reply #32 on: 11 Feb 2019, 15:42 »
Code: Adventure Game Studio
  1.  BEnemy1.X = cEnemy1.x/50  + (BEnemy1.Width) / 5;
  2.   BEnemy1.Y = cEnemy1.y/50  + (BEnemy1.Width) / 5;
  3.  
  4.   bGreenDot.X = viewportX/50 + (bGreenDot.Width) /5;
  5.   bGreenDot.Y = viewportY/50 - (bGreenDot.Width) /5;

Got it to working im still about one radar blip over from the enemy when I go looking for him but other then that it works perfect any ideas why.



« Last Edit: 11 Feb 2019, 22:36 by jamesreg »

Snarky

  • Global Moderator
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
Re: Scrolling screen background issues
« Reply #33 on: 11 Feb 2019, 17:03 »
Could the scripting we did for this room with the mouse always being called to the center be effecting trying to get a radar system working?

this is code I tried having it go by mouse
Code: Adventure Game Studio
  1.  bGreenDot.X = mouse.x/75 + (bGreenDot.Width) / 5;
  2.   bGreenDot.Y =  mouse.y/80 + (bGreenDot.Width) / 5;

Sort of, but the actual problem here is that you're not taking account of the viewport.

In AGS, X and Y coordinates come in two flavors. Some things are in room coordinates, while other things are in screen coordinates. Room coordinates are for things that exist "in the room", logically enough, like characters, objects, hotspots/regions etc., while screen coordinates are for things that shouldn't move just because you're scrolling around in the room, so stuff like GUIs and your mouse cursor (you normally don't want your cursor to disappear off-screen just because the room scrolls away from where it was).

To convert between them, you have to consider the Viewport location. This allows you to convert back and forth:

Code: Adventure Game Studio
  1.   roomX = screenX + GetViewportX();
  2.   screenY = roomY - GetViewportY();

Quote
I even tried other ways to make it work like turning cEgo into an invisible character and have him follow the mouse and do if character is over hotspot but hes not walking just following mouse so I tried if mouse is over hotspot and it seems to not recognize mouse over hotspot processes eighter.

Yeah, stop doing that. I'm not sure why you thought that would help. In fact, why are you using hotspots at all?

Re: Scrolling screen background issues
« Reply #34 on: 11 Feb 2019, 17:41 »
I was using hot spots because we are not all master coders so I figured if I made hotspots I could mouse over them and then tell the button to move that way. 90 percent of what I want to do later can be done in the panels or basic interactions but this part of game you have to know how to code to do it.


Original code now I need the two bGreendot lines in the format you gave me.

Code: Adventure Game Studio
  1. BEnemy1.X = cEnemy1.x/75  + (BEnemy1.Width) / 5;
  2.   BEnemy1.Y = cEnemy1.y/80  + (BEnemy1.Width) / 5;
  3.  
  4.   bGreenDot.X = mouse.x/75 + (bGreenDot.Width) / 5;
  5.   bGreenDot.Y =  mouse.y/80 + (bGreenDot.Width) / 5;
  6.  

ok so you told me
Code: Adventure Game Studio
  1. roomX = screenX + GetViewportX();
  2.   screenY = roomY - GetViewportY();


Now ill try to see if I can figure out how to write that out.
I understand what the formula means and what it is meant to do.
I just have to play with it till I get it right now.


EDIT
I am till having trouble understanding how I need to code the player radar part. I understand what your code says and is supposed to do but I am still confused on the whole room vs view port coordinates things but making progress the scrolling i done, almost have weapons working and almost have radar if I can get to that point I can combine a lot of other things I already done and be on my own for awhile Im just still confused how to write this out and want to understand how to better understand the room vs viewport thing.
« Last Edit: 11 Feb 2019, 22:11 by jamesreg »

Re: Scrolling screen background issues
« Reply #35 on: 11 Feb 2019, 22:20 »

 
I got this moving some now but I think it is my numbers which are off or maybe im still doing it totally wrong

Code: Adventure Game Studio
  1.  bGreenDot.X = viewportX/75 + (bGreenDot.Width) /5;
  2.   bGreenDot.X = viewportX/80 - (bGreenDot.Width) /5;

it moves side to side just fine (except it wraps a couple grids to early on the map)
It does not move the blip up or down at all.

But I am running into my enemy at about the right location good news.

Disregard the above

Code: Adventure Game Studio
  1. BEnemy1.X = cEnemy1.x/50  + (BEnemy1.Width) / 5;
  2.   BEnemy1.Y = cEnemy1.y/50  + (BEnemy1.Width) / 5;
  3.  
  4.   bGreenDot.X = viewportX/50 + (bGreenDot.Width) /5;
  5.   bGreenDot.Y = viewportY/50 - (bGreenDot.Width) /5;
  6.  

found my typos and changed the numbers to the size of the gui and it works except for beight roughly half or a full radar blip apart from the enemy when I go looking for him is this due to the fact the enemy is a character and the player is a viewport and I need to compensate for that?
Im slowly starting to understand
« Last Edit: 11 Feb 2019, 22:49 by jamesreg »