Block scrolling

Started by Peegee, Wed 03/08/2022 07:15:19

Previous topic - Next topic

Peegee

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: ags

//Viewport Scroll
  if (player.x > 300) {
    while (ViewportX < 250) {
    ViewportX = (ViewportX) +5;
    SetViewport(ViewportX, 0);
    Wait (1);
    }
  }
  else {
    while (ViewportX > 10) {
    ViewportX = (ViewportX) -5;
    SetViewport(ViewportX, 0);
    Wait (1);
    }

Someone would have any idea ?

Khris

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: ags
  if (!Camera.AutoTracking) Game.Camera.SetAt(250, player.y - 100);


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

Crimson Wizard

#2
"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

Peegee

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: Ags

Game.Camera.AutoTracking=false;

or with this:
Code: Ags

Game.Camera.SetAt(1438, 860);


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

Snarky

Did you try putting the code Khris suggested in your room script? In full, it should look something like this:

Code: ags
function late_repeatedly_execute_always()
{
  if (!Game.Camera.AutoTracking)
    Game.Camera.SetAt(1438, player.y - 100);
}


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.

Peegee

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 "!"   ?

Crimson Wizard

Quote from: Peegee on Wed 03/08/2022 16:38:41
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

Quote from: Peegee on Wed 03/08/2022 16:38:41
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

Peegee

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: ags

function room_RepExec()
{
Game.Camera.AutoTracking=false;

}

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

function hHotspot9Travo_Interact()
{
Game.Camera.AutoTracking=true;    
Game.Camera.SetAt(800, player.y - 300);

}
[code/]

Snarky

#8
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().

Peegee

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?

Crimson Wizard

#10
In the code you posted above, you have this:

Code: ags

function hHotspot9Travo_Interact()
{
Game.Camera.AutoTracking=true;    
Game.Camera.SetAt(800, player.y - 300);
}


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.

Peegee

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

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!


SMF spam blocked by CleanTalk