Continuous scrolling?

Started by FrankT, Sat 22/12/2012 12:41:51

Previous topic - Next topic

FrankT

Is it possible to continuously scroll the background of a room without running into any edges?

Ghost

You mean a looping room? Yes, that is possible, but it requires some trickery. Or do you want an automatically scrolling room "animation"?

MurrayL

You can use the SetViewport(int x, int y) command to manually move the viewport around in a scrolling room. It'll lock the view to the specified position until you either call ReleaseViewport or leave the room.

To get a room to scroll continuously is a bit trickier, since you'll have to somehow deal with wrapping it around at one end, but it's certainly possible.

FrankT


Ghost

One way to create a scrolling room is to make a large background, and copy a section of the left side to the right side- it must be at least half the screen's width wide. So let's say you have a 500x240 background at 320x240, then you take the left 160 wide bit at copy to to the right, creating a 660x240 room.
In-game, you check if the player is at x:500, and then move him back to x:0. It's impossible to notice because the "right edge" is the same as the "left edge".

I think the age-old "Loopy's Looping Room" in the original AGS demo game did it just like that. Bet there's other ways too.

Crimson Wizard

I am actually wondering, does FrankT needs scrolling room or scrolling background?
Because, technically speaking, this is two different things.

If you scroll the room (by moving viewport) you just change camera's point of view, which will make everything else in the room (characters, objects, hotspots) "move" other direction as well.
If you scroll only background picture, everything else will stay in place. (You may do this by setting a large object and move it, simulating background scroll).

What do you need depends on what are you trying to achieve in the end.
If you want to simulate road driving (or horse riding, or flying a plane, or similar kind of endless movement), the second variant is better, in my opinion. But again, this depends on goal and specifics.

FrankT

Background scrolling! Yes - how do I do that?

Crimson Wizard

#7
Quote from: FrankT on Sun 23/12/2012 19:39:22
Background scrolling! Yes - how do I do that?

Simple example.
Place an object in the room, let's call it oBackground.
Apply background graphic to oBackground object.
Most easy way is to make the graphic consist of two copies of the same picture, with second copy applied to the right end of the first. Let's assume your room is 320 pixels wide, in this case you'll need 320x2 = 640 pixels wide graphic.

Now, put this into room's room_RepExec function:
Code: ags

function room_RepExec()
{
  if (oBackground.X > -Room.Width)
  {
    oBackground.X = oBackground.X - 1;
  }
  else
  {
    oBackground.X = 0;
  }
}

This code will make this imporivised "background" scroll left.

The only problem is to draw the graphic the way that will make it look as a seamless picture. But that's drawing question. Hopefully someone will post an example.

Also, you may use more than one object this way, if you find it more convenient (like one object for far background, other for foreground etc).

kinan___rod

#8
I made a 640 width background and placed two hotspots on left and right to teleport the character, there is a small jump in where the loop triggers but it is hard to notice.
Code:
Code: AGS
// room script file
function hHotspot2_WalkOn()
{
 cEgo.x = 475;
 cEgo.Walk(375, cEgo.x);
}
function hHotspot1_WalkOn()
{
 cEgo.x = 165;
 cEgo.Walk(265, cEgo.x);
}

Sample:
http://www.mediafire.com/?74vc7o8qmbjx5sb

Crimson Wizard

This depends on what you are trying to do. In some cases this may be done by moving character, in other by scrolling an object.

For example, if character should remain controllable and move around the room in any direction.

FrankT did not explained what he wants in detail, and since other people already mentioned setting Viewport/moving Character methods, I added scrolling object variant.


FrankT

Ah, well, this is for the opening credit sequence; no character movement, except maybe for a few comets.

MiteWiseacreLives!

Invisible Character walking across x-axis and a looped background like the other guys described..
I am new, but I think this is what your getting at??

Crimson Wizard

Quote from: FrankT on Mon 24/12/2012 13:24:48
Ah, well, this is for the opening credit sequence; no character movement, except maybe for a few comets.
I think that Viewport manipulation could be more useful in such case. No extra object/hotspots needed.

Assuming you made scrollable room twice wider than your game's screen width (e.g. 640 for 320x* game):
Code: ags

function room_RepExec()
{
  if (GetViewportX() < Room.Width / 2)
  {
    SetViewport(GetViewportX() + 1, 0);
  }
  else
  {
    SetViewport(0, 0);
  }
}

FrankT

Excellent! Is there a way to control the speed at which it scrolls?

Crimson Wizard

Quote from: FrankT on Mon 24/12/2012 20:23:02
Excellent! Is there a way to control the speed at which it scrolls?
The speed is defined by how often you change the coordinates, of course, and by which amount.
Adjust by either setting up a delay between each viewport change or amount of pixels you add every time (but for low-res game jumping over few pixels at once may look bad).
By setting a delay I do not mean Wait command (it won't do any good here, because we need continious action), but counting how much frames game passed:

Code: ags

int room_scroll_delay;
function room_RepExec()
{
  room_scroll_delay = room_scroll_delay + 1;
  if (room_scroll_delay >= 4)
  {
    room_scroll_delay = 0;
    if (GetViewportX() < Room.Width / 2)
    {
      SetViewport(GetViewportX() + 1, 0);
    }
    else
    {
      SetViewport(0, 0);
    }
  }
}

This example will make it move by one pixel every 4th frame (assuming 40 frames per second - 40/4 = 10 times per second).

FrankT

Excellent, thank you very much for that!

SMF spam blocked by CleanTalk