Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Glenjamin on Wed 04/10/2017 20:52:50

Title: SetViewport.Y while X stays the same [SOLVED]
Post by: Glenjamin on Wed 04/10/2017 20:52:50
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) Select

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


and

Code (ags) Select

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?
Title: Re: SetViewport.Y while X stays the same
Post by: dayowlron on Wed 04/10/2017 21:01:06
you could put in Rep_Exec:

    if (player.y<200) SetViewport(player.x - 160,0);
    else SetViewport(player.x - 160,200);
Title: Re: SetViewport.Y while X stays the same
Post by: Glenjamin on Wed 04/10/2017 21:21:37
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?
Title: Re: SetViewport.Y while X stays the same
Post by: Crimson Wizard on Wed 04/10/2017 21:30:55
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.
Title: Re: SetViewport.Y while X stays the same
Post by: Glenjamin on Wed 04/10/2017 21:43:45
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!