Center character in scrolling room [SOLVED]

Started by Glenjamin, Fri 27/04/2018 15:40:58

Previous topic - Next topic

Glenjamin

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?

dayowlron

#1
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.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Crimson Wizard

#2
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();

Glenjamin

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.

SMF spam blocked by CleanTalk