Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Mon 16/05/2011 20:00:55

Title: ReleaseViewport question [found workaround]
Post by: HandsFree on Mon 16/05/2011 20:00:55
Hi,

I have used SetViewport to lock a scrollable screen in a set position.
Now when the player is allowed to move around the full screen again I used ReleaseViewport.
However the screen makes a jump to place the player in the center of the screen.

How can I keep the screen the way it is (with the player off-center) and then allow the player to walk around the full screen?

thanks
Title: Re: ReleaseViewport question
Post by: hedgefield on Mon 16/05/2011 20:23:26
Using the built-in viewport handling there's not really a way to do that. But you may get fairly close to what you need with the Smoothscroll module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=33142.0).

I recently did a similar thing with 15 Minutes (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=43532.0) where I shift the center of the viewport to make room for a splitscreen frame while keeping the character centered in his own frame. But even then jumps were hard to avoid. I discussed possible workarounds with Ali (the author of the Smoothscroll module), but we haven't discovered a definitive method yet. Though contacting him once you've implemented the Smoothscroll module would probably be your best bet.
Title: Re: ReleaseViewport question
Post by: Khris on Mon 16/05/2011 20:29:17
If you simply want to avoid the jump, turn the scrolling back on when the player is in the center of the screen. (This might not be possible with your current way of scrolling though.)
Another way would be to gradually move the viewport so the player is centered again, then turn scrolling back on.

Or do you want another way of scrolling altogether i.e. the room scrolls but the player remains off-center?

Please provide us with a bit more info.
Title: Re: ReleaseViewport question
Post by: HandsFree on Mon 16/05/2011 21:08:08
@Hedgefield: At this point I'm still finding out how AGS works, and using a module is a bit beyond scope for now.
I'll have a look at that later though, when I'm more comfortable with the basics.

@Khris: Yes, I only want to avoid the jump. By 'turn the scrolling back on' you mean ReleaseViewport, or is there another way?

It's a normal scrolling room (the RON town square), and at the start of a certain section I used SetViewport to lock the screen. Then I have a npc walk into the screen and there is some talking and when the player gets control again the character is near the right side of the screen.
From that point I wanted the game to behave 'normal' again. So when you walk further to the right (not passing center screen) the background would scroll as normal.

The way it is now, the screen jumps to put the player character in the center the moment ReleaseViewport is called.

If this is unavoidable, I'll setup that scene a bit differently. As said, I'm just in the process of finding out how everything works.
Title: Re: ReleaseViewport question
Post by: Khris on Mon 16/05/2011 21:24:58
A very simple solution would be a blocking loop at the end of the scene, like this:

 int x1 = GetViewportX();      // scroll from x1
 int x2 = player.x - System.ViewportWidth/2;    // to x2
 int step = x2 - x1;
 if (step < 0) step = -1; else step = 1;
 while (x1 != x2) {
   x1 += step;
   SetViewport(x1, GetViewportY());
    Wait(1);
 }
 ReleaseViewport();


Edit: forgot Wait()
Title: Re: ReleaseViewport question
Post by: HandsFree on Mon 16/05/2011 22:09:48
I tried this, but the screen still makes a jump.
Maybe because the statements in the while loop are executed too fast?
Title: Re: ReleaseViewport question
Post by: Khris on Mon 16/05/2011 22:24:33
Right, I completely forgot about the Wait() command.
Title: Re: ReleaseViewport question
Post by: HandsFree on Tue 17/05/2011 22:44:59
OK, this is close enough for now, thanks.
Maybe later I'll try that module to see if I can stop the background from moving altogether.