Hello,
does anyone know if there's still a download link to the old AGS verson with the looping room in the demo game somewhere? I'd like to do something like that and there are several threads in the forums about looping rooms and endless backgrounds. But I can't figure it out completely. So I'd like to have a look at the original script to see how it works.
Thanks a lot.
Adrian
[EDIT]: zabnat provided some code and an explanation of how looping rooms work in this thread here (http://www.adventuregamestudio.co.uk/forums/index.php?topic=47644.msg636446235#msg636446235).
I am quite sure that this old demo is lost, safe for a copy a member might have saved. The basic principle is pretty simple though- and if I remember the old demo correctly it was not THAT well documented. It might be easier to post what you have, and have us supply the rest.
And THEN make this thread a sticky, because looping rooms seem to be rather popular.
Thank you, Ghost.
After different approaches using hotspots, room edges and so on, I decided to use strazer's code from this old post (http://www.adventuregamestudio.co.uk/forums/index.php?topic=20269.msg247140#msg247140).
Here's my (nearly the same) verson:
#define BUFFERAREA_LENGTH 120 // relative width of room background buffer area (335 pixels)
function PauseMoving (int charid) {
// Stops the supplied character but keeps its last frame
// For seamlessly changing walking speed, for example
char prevview = character[charid].View;
char prevloop = character[charid].Loop;
char prevframe = character[charid].Frame;
int wasmoving = character[charid].Moving;
character[charid].StopMoving();
if (wasmoving) character[charid].LockViewFrame(prevview, prevloop, prevframe);
// since we're using his current view, the lock will be released automatically once the character is moved again
}
function WaitHidden(int gameloops) {
int prevmode = Mouse.Mode; // store the current cursor mode
Mouse.Mode = eModeWait; // change to wait cursor mode
Mouse.UseModeGraphic(prevmode); // change appearance to look like previous cursor mode
Wait(gameloops);
Mouse.ChangeModeGraphic(eModeWalkto, 339); // revert wait cursor to the default sprite
Mouse.Mode = eModeWalkto; // revert to previous cursor mode
}
function on_mouse_click(MouseButton button) {
if (IsGamePaused()) return; // if game is paused, quit function
if (button == eMouseLeft) { // if left mouse click
if (Mouse.Mode == eModeWalkto) { // if mouse is in walk mode
if (GetViewportX() + mouse.x >= Room.Width - (System.ViewportWidth / 2)) { // if clicked on right end of room
PauseMoving(0); // see above
character[player.ID].x = character[0].x - (Room.Width - BUFFERAREA_LENGTH); // put character at left end of room
WaitHidden(1); // see above; let screen update before running global on_mouse_click
character[player.ID].x = GetViewportX() + 160;
}
else if (GetViewportX() + mouse.x <= (System.ViewportWidth / 2)) { // if clicked on left end of room
PauseMoving(0); // see above
character[player.ID].x = character[0].x + (Room.Width - BUFFERAREA_LENGTH); // put character at right end of room
WaitHidden(1); // see above; let screen update before running global on_mouse_click
character[player.ID].x = GetViewportX() + 160;
}
}
}
// global on_mouse_click will be called afterwards -> character starts walking
}
It actually works quite well but there are some issues.
1. I had difficulties defining the value for the buffer area, meaning the range inside which a mouse click would change the PC's x-coordinates. Via trial-and-error I figured out that a value around 120 works best, but I don't know why because the overlapping area of the background has 335 pixels.
2. I had to add this code line at the end of the function:
character[player.ID].x = GetViewportX() + 160;
Otherwise the player character would nearly never be placed in the middle of the screen as expected. But I don't know if this is a good solution because of that there's a short flicker when the PC's coordinates are being changed.
3. This is most irritating: When you click inside the buffer area and that mouse click is made closer to the edge of the screen, the character gets not „teleported“ to the right coordinates. It looks like the character jumps forwards, or to be precise the background jumps. While when you make the click within the buffer area closer to the center of the screen, it looks much better!
4. Also I was wondering what modifications I woud have to do to make a looping room also possible with a NPC following the player character and if this is even possible.
For testing the whole thing I use the nexus background (https://dl.dropbox.com/u/11927285/AGS/nexus.png) from the game The Dig.
It's 1808 pixels wide, of which 335 pixels contain the necessary overlapping area, copied from the left side of the picture.
Thanks to anyone for having a look at it. I hope that wasn't too confusing.
I think making a good and stable looping room is not that easy at all, but I'm hoping to get it sometime.
Adrian
I got interested and tried this. I copied strazer's code and modified it to get it run on AGS 3.21 (with object based scripting).
The main points are:
- BUFFERAREA_LENGTH is the actual area that overlaps in the background image.
- Overlapping area should be 1.5 times screen width. Anything smaller will cause jumping you talk about. This is why. Considering screen resolution of 320x200 in this example. You change the position of the character when user clicks the first or last 160 pixels in room (widthwise). And because character is in the middle of the screen, the first time player is able to click the last 160 pixels of the room is when player is at game.room_width-320+1. So from this you can see that overlap needs to be 480 pixels. If you use smaller overlap area the character will be moved to the right place related to background graphics, but might not be on the center of the screen because at the ends background stops moving and it is the player that moves closer to the edge. You can see this point illustrated in the test source (http://bantza.raah.fi/junk/Looptest.zip)
ps. Remember to paint hotspots on overlapping area to the other end of the room also and move the possible objects and other characters as well.
Here's the room code I used.
// room script file
#define BUFFERAREA_LENGTH 480 // relative width of room background buffer area (area that overlaps)
function PauseMoving (int charid) {
// Stops the supplied character but keeps its last frame
// For seamlessly changing walking speed, for example
int prevview = character[charid].View;
int prevloop = character[charid].Loop;
int prevframe = character[charid].Frame;
bool wasmoving = character[charid].Moving;
if (wasmoving) {
character[charid].StopMoving();
character[charid].LockViewFrame(prevview, prevloop, prevframe);
}
// since we're using his current view, the lock will be released automatically once the character is moved again
}
function WaitHidden(int gameloops) {
int prevmode = mouse.Mode; // store the current cursor mode
mouse.Mode = eModeWait; // change to wait cursor mode
mouse.UseModeGraphic(prevmode); // change appearance to look like previous cursor mode
Wait(gameloops);
mouse.UseDefaultGraphic(); // revert wait cursor to the default sprite
mouse.Mode = prevmode; // revert to previous cursor mode
}
function on_mouse_click(MouseButton button) {
if (IsGamePaused()) return; // if game is paused, quit function
if (button == eMouseLeft) { // if left mouse click
if (mouse.Mode == eModeWalkto) { // if mouse is in walk mode
if (GetViewportX() + mouse.x >= game.room_width - (system.viewport_width / 2)) { // if clicked on right end of room
PauseMoving(player.ID); // see above
player.x = player.x - (game.room_width - BUFFERAREA_LENGTH); // put character at left end of room
WaitHidden(1); // see above; let screen update before running global on_mouse_click
}
else if (GetViewportX() + mouse.x <= (system.viewport_width / 2)) { // if clicked on left end of room
PauseMoving(player.ID); // see above
player.x = player.x + (game.room_width - BUFFERAREA_LENGTH); // put character at right end of room
WaitHidden(1); // see above; let screen update before running global on_mouse_click
}
}
}
// global on_mouse_click will be called afterwards -> character starts walking
}
Thank you very much for your effort and support, zabnat! Due to your very good explanation and test source I was able to install the looping room just the way it should be and it works perfectly. Now I can start to add all the walkable areas, objects, NPCs etc.
I'm sure this thread will be of use for many beginners who don't know how to install a looping room.