Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Tue 20/09/2022 14:12:54

Title: Scrollable room camera
Post by: Slasher on Tue 20/09/2022 14:12:54
Hi,

I've always been used to GetViewport but it seems Camera is the new way.

Ok. You get into a lift. Press floor button (gui) Lift and Char rises/lowers to the floor chosen. The lift arrives at the floor with character inside but the room top is not visible because the character is low in the room.... i need to the screen to show whole room with the char at the bottom in lift.  Room scrollable is 300wide  x 820high....

Hope you understand my issue.

Thank you..


Title: Re: Scrollable room camera
Post by: Crimson Wizard on Tue 20/09/2022 14:25:16
Quote from: Slasher on Tue 20/09/2022 14:12:54i need to the screen to show whole room with the char at the bottom in lift.  Room scrollable is 300wide  x 820high....

Do you mean that you need to move the camera up, or zoom camera out to show more of the room at once?

Regarding old functions (GetViewport and so on), if you search for them in the manual, their description has a note that tells which functions to use instead.
Also, there's a table of outdated functions, which tells the replacements:
https://adventuregamestudio.github.io/ags-manual/ObsoleteScriptAPI.html
Title: Re: Scrollable room camera
Post by: Snarky on Tue 20/09/2022 14:25:56
You use

Camera.SetAt(int x, int y);

the same way you'd previously use

SetViewport(int x, int y);

In this case you'd probably want to scroll it up so Camera y=0.
Title: Re: Scrollable room camera
Post by: Slasher on Tue 20/09/2022 14:36:27
Cheers guys but...

GlobalScript.asc(1094): Error (line 1094): must have an instance of the struct to access a non-static member
Title: Re: Scrollable room camera
Post by: Khris on Tue 20/09/2022 15:28:10
Afaik you need

Code (ags) Select
  Game.Camera.SetAt(...);
Title: Re: Scrollable room camera
Post by: Crimson Wizard on Tue 20/09/2022 15:52:59
We need better code examples in the manual... because currently it has none.
Also I just realized that Camera's article does not mention the Game.Camera object, so there's no obvious connection.
Title: Re: Scrollable room camera
Post by: Slasher on Tue 20/09/2022 17:08:23
Thanks a lot guys  (nod)
Title: Re: Scrollable room camera
Post by: Nahuel on Tue 20/09/2022 22:08:38
I thin you can also follow up the lift movement also and follow with x y the camera I use it for panning the room while on cutscenes.
int i=0;
while ( i<=53 ){
  i++;
  Game.Camera.SetAt(Game.Camera.X - 6, Game.Camera.Y);
  Wait(4);
}
Title: Re: Scrollable room camera
Post by: Crimson Wizard on Tue 20/09/2022 22:16:53
Strictly speaking, the above code may be simplified, as you already have X coordinate that you may use in a condition:
Code (ags) Select
while ( Game.Camera.X > X_DESTINATION ){
  Game.Camera.SetAt(Game.Camera.X - 6, Game.Camera.Y);
  Wait(4);
}

Or simplified even more:
Code (ags) Select
while ( Game.Camera.X > X_DESTINATION ){
  Game.Camera.X -= 6;
  Wait(4);
}

Naturally, vertical movement will require changing Y instead; and moving in opposite direction will require adding instead of subtracting and testing for (Camera.X < X_DESTINATION).
Title: Re: Scrollable room camera
Post by: Crimson Wizard on Wed 21/09/2022 00:05:28
I expanded the Camera and Viewport articles with practical examples and minor additions; they are not published in the official manual yet, but may be read in the wiki source:
https://github.com/adventuregamestudio/ags-manual/wiki/Camera
https://github.com/adventuregamestudio/ags-manual/wiki/Viewport
Title: Re: Scrollable room camera
Post by: AndreasBlack on Mon 26/09/2022 07:29:51
If you aren't already. Use the tweenmodule, it works great for elevators and all kinds of camera movements. (nod)