Jibble

There is a new version of the forums ready for testing. Please post here if you're willing to help test! We could also use the help of coders!

Author Topic: Block scrolling  (Read 321 times)

Block scrolling
« on: 03 Aug 2022, 07:15 »
Hello, I would like to block background scrolling (in x), to unblock it later.

I found this code but the software does not support "ViewportX":
Code: Adventure Game Studio
  1. //Viewport Scroll
  2.   if (player.x > 300) {
  3.     while (ViewportX < 250) {
  4.     ViewportX = (ViewportX) +5;
  5.     SetViewport(ViewportX, 0);
  6.     Wait (1);
  7.     }
  8.   }
  9.   else {
  10.     while (ViewportX > 10) {
  11.     ViewportX = (ViewportX) -5;
  12.     SetViewport(ViewportX, 0);
  13.     Wait (1);
  14.     }
  15.  
Someone would have any idea ?

Re: Block scrolling
« Reply #1 on: 03 Aug 2022, 09:49 »
The API has changed recently; please check the Camera and Viewport sections of the manual.
I haven't used it yet but from a quick glance at the manual, something like this inside Room_RepExec might work:

Code: Adventure Game Studio
  1.   if (!Camera.AutoTracking) Game.Camera.SetAt(250, player.y - 100);

Now call  Camera.AutoTracking = false; at any point.

Re: Block scrolling
« Reply #2 on: 03 Aug 2022, 13:56 »
"ViewportX" in the above code is likely a global variable that you were supposed to create yourself.

On another hand, "SetViewport" is an old function that was replaced by Game.Camera.
Speaking of which, the manual now has a table of deprecated functions, which also mentions contemporary replacements:
https://adventuregamestudio.github.io/ags-manual/ObsoleteScriptAPI.html
« Last Edit: 03 Aug 2022, 13:59 by Crimson Wizard »

Re: Block scrolling
« Reply #3 on: 03 Aug 2022, 14:27 »
Thank you for your answers. But it doesn't work like that, even putting the code "Game.Camera.SetAt(250, player.y - 100);" Between { }

I'm not a programmer, I'm not doing with the manual. The codes are not explained enough for me, the software does not take them.

I managed to block the scrolling with:
Code: Adventure Game Studio
  1. Game.Camera.AutoTracking=false;
  2.  
or with this:
Code: Adventure Game Studio
  1. Game.Camera.SetAt(1438, 860);
  2.  

But I would like to block scrolling only in X, and I can't manage to unblock it.

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Block scrolling
« Reply #4 on: 03 Aug 2022, 15:59 »
Did you try putting the code Khris suggested in your room script? In full, it should look something like this:

Code: Adventure Game Studio
  1. function late_repeatedly_execute_always()
  2. {
  3.   if (!Game.Camera.AutoTracking)
  4.     Game.Camera.SetAt(1438, player.y - 100);
  5. }

You should then be able to block scrolling along the x-axis by setting Game.Camera.AutoTracking = false; and unblock it by setting it to true.

Re: Block scrolling
« Reply #5 on: 03 Aug 2022, 16:38 »
Where do I find this function: function late_repeatedly_execute_always()    ?
I know "Repeatedly Execute", but the code doesn't change anything in it.

What means the "!"   ?

Re: Block scrolling
« Reply #6 on: 03 Aug 2022, 16:44 »
Where do I find this function: function late_repeatedly_execute_always()    ?

You add it yourself, for example in the room script.
Related articles in the manual:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html
https://adventuregamestudio.github.io/ags-manual/RepExec.html

What means the "!"   ?

"!" means a logical NOT, it inverses the result of the following expression: from "true" to "false" and vice versa.
https://adventuregamestudio.github.io/ags-manual/ScriptKeywords.html#operators

Re: Block scrolling
« Reply #7 on: 03 Aug 2022, 18:30 »
OK, thanks. Yes, there is better. Scrolling in x is blocked, and I keep scrolling in y. On the other hand, I cannot recover the scrolling in x after having clicked on Hotspot9Travo.

Code: Adventure Game Studio
  1. function room_RepExec()
  2. {
  3. Game.Camera.AutoTracking=false;
  4.  
  5. }
  6.  
  7. function late_repeatedly_execute_always()
  8. {
  9.    if (!Game.Camera.AutoTracking)
  10.    Game.Camera.SetAt(800, player.y - 300);
  11. }
  12.  
  13. function hHotspot9Travo_Interact()
  14. {
  15. Game.Camera.AutoTracking=true;    
  16. Game.Camera.SetAt(800, player.y - 300);
  17.  
  18. }
  19. [code/]

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Block scrolling
« Reply #8 on: 03 Aug 2022, 18:32 »
The problem is that you have Game.Camera.AutoTracking=false; in room_RepExec(). This means that you're turning AutoTracking off every game loop, so it will always be off.

Instead, you should place this command where you want it to trigger. When during gameplay do you want scrolling to be blocked? For example, if you want it to be from the start when the player enters the room, you should put it in function room_Load().
« Last Edit: 03 Aug 2022, 18:38 by Snarky »

Re: Block scrolling
« Reply #9 on: 03 Aug 2022, 20:39 »
Yes, it's for the start of the game, so I set

Game.Camera.AutoTracking=false;

in the room load but I still don't get my scrolling back afterwards.
I tried putting

    if (!Game.Camera.AutoTracking)
    Game.Camera.SetAt(800, player.y - 300);

in the rom load too...

The last code, to restart the scroling, doesn't work, I just managed to have a camera in another place in x, but still.
Is there a variable I should create to re-enable autotracking?

Re: Block scrolling
« Reply #10 on: 03 Aug 2022, 21:03 »
In the code you posted above, you have this:

Code: Adventure Game Studio
  1. function hHotspot9Travo_Interact()
  2. {
  3. Game.Camera.AutoTracking=true;    
  4. Game.Camera.SetAt(800, player.y - 300);
  5. }
  6.  

Here you enable AutoTracking with "Game.Camera.AutoTracking=true;"  , but then immediately lock it again with Camera.SetAt. Camera.SetAt command turns AutoTracking off
https://adventuregamestudio.github.io/ags-manual/Camera.html#camerasetat
So, it never gets enabled again.

If you need to only enable camera following a player, then do "AutoTracking = true" and nothing else.
« Last Edit: 03 Aug 2022, 21:07 by Crimson Wizard »

Re: Block scrolling
« Reply #11 on: 03 Aug 2022, 21:28 »
Ok good ! It seems to work.

Sorry, I'm having trouble understanding these functions, just with the manual.

Thank you, you have allowed Gobliiins5, level 11, to progress well !!    PG

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Block scrolling
« Reply #12 on: 03 Aug 2022, 21:31 »
Great! Hope you're gradually figuring out how AGS works.

Good luck on the game—it's exciting that a new official Gobliiins title is being made in AGS!

Re: Block scrolling
« Reply #13 on: 04 Aug 2022, 08:07 »
 ;)