ReleaseViewport question [found workaround]

Started by HandsFree, Mon 16/05/2011 20:00:55

Previous topic - Next topic

HandsFree

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

hedgefield

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.

I recently did a similar thing with 15 Minutes 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.

Khris

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.

HandsFree

@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.

Khris

#4
A very simple solution would be a blocking loop at the end of the scene, like this:

Code: ags
  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()

HandsFree

I tried this, but the screen still makes a jump.
Maybe because the statements in the while loop are executed too fast?

Khris

Right, I completely forgot about the Wait() command.

HandsFree

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.

SMF spam blocked by CleanTalk