SetViewport.Y while X stays the same [SOLVED]

Started by Glenjamin, Wed 04/10/2017 20:52:50

Previous topic - Next topic

Glenjamin

My game has a tall 400px background.

I want to lock the ViewPort's Y depending on what half of the screen the player is on, so the half of the background is only in view.

I moved the Top and bottom edges to the center of the screen, and added this:

Code: ags

function room_LeaveTop()
{
  SetViewport(player.x - 160 , 0);
}


and

Code: ags

function room_LeaveBottom()
{
  SetViewport(player.x - 160 , 200);
}


This works like a charm, except it makes the player character vibrate when moving horizontally which is a deal breaker.

Is there a way to only set the Viewport's Y, and have X behave normally so it scrolls with the player?

dayowlron

you could put in Rep_Exec:
Code: ags

    if (player.y<200) SetViewport(player.x - 160,0);
    else SetViewport(player.x - 160,200);
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

Glenjamin

Quoteyou could put in Rep_Exec:

This works the same as what I had, however the character still vibrates while moving horizontally.

I'm fairly certain the problem is in the SetViewPort function, not where the function is.

Is it possible to set the Viewport Y without setting the X?

Crimson Wizard

#3
Quote from: Glenjamin on Wed 04/10/2017 21:21:37
Is it possible to set the Viewport Y without setting the X?


Technically this:
SetViewport(GetViewportX(), y);
you will tell it to keep X that it has. But the issue here is that by setting a viewport you are taking control over camera from AGS, and it no longer automatically moves it, so that will defeat the purpose.

Actually that's dumb anyway, so disregard that.

Considering character vibrating, I may propose to move the code into "late_repeatedly_execute_always" and see if that helps. IIRC that helped me in the past.

Glenjamin

QuoteConsidering character vibrating, I may propose to move the code into "late_repeatedly_execute_always" and see if that helps. IIRC that helped me in the past.

This worked perfectly! animation is smooth and the camera movement works.

Thanks!

SMF spam blocked by CleanTalk