Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Glenjamin on Fri 27/04/2018 15:40:58

Title: Center character in scrolling room [SOLVED]
Post by: Glenjamin on Fri 27/04/2018 15:40:58
I'm making a game with a large scrolling room and a very tall player character.

Because of the player's height, he's never truly centered in the screen and takes up too much of the top half.

How can I make the view-port anchored to a different part of the character?
Title: Re: Center character in scrolling room
Post by: dayowlron on Fri 27/04/2018 16:13:47
in repeatedly executing function you could adjust the viewport yourself.
If you need help doing that I am sure someone could provide code or look up SetViewPort in the manual.
Title: Re: Center character in scrolling room
Post by: Crimson Wizard on Fri 27/04/2018 16:22:08
Something like this in repeatedly_execute_always:

SetViewport(cCharacter.x + Nx - System.ViewportWidth / 2, cCharacter.y + Ny - System.ViewportHeight / 2);

Where Nx and Ny are some distances from character's x and y, which you need to define yourself.
And half of the viewport sizes need to be subtracted, because SetViewport sets top-left corner in room coordinates, while character has to be centered.

When you are done (e.g. leaving the room or changing character view): ReleaseViewport();
Title: Re: Center character in scrolling room
Post by: Glenjamin on Fri 27/04/2018 16:37:31
QuoteSomething like this in repeatedly_execute_always:

SetViewport(cCharacter.x + Nx - System.ViewportWidth / 2, cCharacter.y + Ny - System.ViewportHeight / 2);

Where Nx and Ny are some distances from character's x and y, which you need to define yourself.
And half of the viewport sizes need to be subtracted, because SetViewport sets top-left corner in room coordinates, while character has to be centered.

When you are done (e.g. leaving the room or changing character view): ReleaseViewport();

Worked like a charm! I changed "repeatedly_execute_always" to "late_repeatedly_execute_always" because the character tends to jump around awkwardly otherwise.