Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Haddas on Mon 28/06/2004 19:20:19

Title: Edge scrolling...
Post by: Haddas on Mon 28/06/2004 19:20:19
I was wondering, for test purpses, how I make the edges scroll when I move my mouse near the edge. I'm trying to do a game with a panoramic view by using edge scrolling and looping to make it seem more 3d-ish. it will most probably stay to a one room game, because I do not know how to make panoramic images. I only have one image which I got from Panoviewer

http://img29.photobucket.com/albums/v86/Haddas/Other/sejourstmathieu2048.jpg

Here is the image I'm using as background
Title: Re: Edge scrolling...
Post by: Ashen on Mon 28/06/2004 19:50:44
The scrolling part is fairly easy, I think:

in rep_ex:
  if (mouse.x < 20) SetViewport (GetViewportX() - 20, GetViewportY());
  if (mouse.x > 300) SetViewport (GetViewportX() + 20, GetViewportY());

The looping part I'm not so sure of.

if (mouse.x < 20) {
  if (GetViewportX() > 0) SetViewport (GetViewportX() - 20, GetViewportY());
  else if (GetViewPortX() == 0) SetViewport (ROOMWIDTH-320, GetViewportY());
}
if (mouse.x > 300) {
  if (GetViewportX() < ROOMWIDTH) SetViewport (GetViewportX() + 20, GetViewportY());
  else if (GetViewPortX() == ROOMWIDTH) SetViewport (0, GetViewportY());
}

This works, but there's a noticable 'jump' when it changes location. Pasting extra image in, like on a normal looping room, would probably sort that out.

Hope this helps.
Title: Re: Edge scrolling...
Post by: Haddas on Mon 28/06/2004 20:14:03
thanks for that :D.

Now, I'm VERY noobish when it comes to the script of ags, so if you could perhaps be as kind as to explain what these all do, so that I know why I'm writing this in and why I get an unexpected 'if' error. Thanks for your trouble :/
Title: Re: Edge scrolling...
Post by: LordHart on Mon 28/06/2004 21:06:33
The if statements are currently wrong. They are calling if and elseif in the same script part, try this instead... the same code pretty much, but the if statements are cleaned up:

in rep_ex:
if (mouse.x < 20) {
    SetViewport (GetViewportX() - 20, GetViewportY());
} else if (mouse.x > 300) {
    SetViewport (GetViewportX() + 20, GetViewportY());
}

if (mouse.x < 20) {
    if (GetViewportX() > 0) SetViewport (GetViewportX() - 20, GetViewportY());
} else if (GetViewPortX() == 0) {
    SetViewport (ROOMWIDTH-320, GetViewportY());
}
if (mouse.x > 300) {
    if (GetViewportX() < ROOMWIDTH) {
        SetViewport (GetViewportX() + 20, GetViewportY());
    } else if (GetViewPortX() == ROOMWIDTH) {
        SetViewport (0, GetViewportY());
    }
}

I think that should fix it up, but I'm a bit tired at the moment... its 6am now and I haven't slept. :-\
Title: Re: Edge scrolling...
Post by: Haddas on Mon 28/06/2004 21:13:20
I still get a complaint about the if statement :(
My, my, why must everything be so hard. Meh, maybe I'll learn someday...
Title: Re: Edge scrolling...
Post by: LordHart on Mon 28/06/2004 21:27:05
Which line does it have problems with? :-\
Title: Re: Edge scrolling...
Post by: Ashen on Mon 28/06/2004 22:42:49
Ultimo:
Actually, the if / else if statements where meant to be in the same script parts, as they both need to be checked for the mouse.x condition. The longer version would be:

if (mouse.x < 20) {
Ã,  if (GetViewportX() > 0) {
Ã,  Ã,  SetViewport (GetViewportX() - 20, GetViewportY());
Ã,  }
Ã,  else if (GetViewPortX() == 0) {
Ã,  Ã,  SetViewport (ROOMWIDTH-320, GetViewportY());
Ã,  }
}

or, the second line could just be 'else', not 'else if'.

Haddas:
It works fine for me, if a little fast. Like Ultimo said, which line is the problem?
Also, although you probably caught this yourself, you need to replace ROOMWIDTH - 320 with the amount needed - SetViewport (448, GetViewportY()); for the image you're using -Ã,  and ROOMWIDTH with the width of the room - in this case 768, unless you resize the image
Title: Re: Edge scrolling...
Post by: Haddas on Tue 29/06/2004 10:58:50
Aaah! You're confusing me more now!11 ::)
Now I got it to scroll to the right and to the left, with xtreme choppyness. The game is in 800x600. I want it to be able to scroll up and down too. I tried to do that on my own and failed. This should give you an idea how much of a noob I am at scripting :P.
Title: Re: Edge scrolling...
Post by: Haddas on Tue 29/06/2004 11:45:04
Nevermind the choppyness. Fixed it. But I still haven't got it to scroll up and down :'(
Title: Re: Edge scrolling...
Post by: Ashen on Tue 29/06/2004 12:48:44
if (mouse.y < 20) if (GetViewportY() > 0) SetViewport (GetViewportX(), GetViewportY()-5);
if (mouse.y > 280) SetViewport (GetViewportX(), GetViewportY()+5);

NOTE: changed 20 pixel movement to 5 pixels - I thought it was a bit too fast before.

But, if you have a pop-up GUI at the top of the screen (like the ICONBAR GUI the default game has) there could be some confusion, as the screen will scroll up when ever you try to access the GUI.
Title: Re: Edge scrolling...
Post by: Haddas on Tue 29/06/2004 13:38:32
thanks :D! that did it. although I have not yet got the room to loop though... ( :P )
Title: Looping the room
Post by: Haddas on Wed 30/06/2004 20:44:07
C'mon, please help. I saw this in the demogame, so I know it can be done. I've reached the wall for my scripting skills... :-\
Title: Re: Edge scrolling...
Post by: Ashen on Wed 30/06/2004 22:34:32
Firstly, you'll need to add the last 400 pixel from the right of your room on to the left, and the first 400 pixels from the left onto the right. Something like this, without the pink lines:
http://www.geocities.com/whoismonkey/scrollbg.png
(Use 'Save Target As...', due to GeoCities)

Then, change the scrolling code to:

if (mouse.x < 20) {
Ã,  if (GetViewportX() > 0) SetViewport (GetViewportX() - 5, GetViewportY());
Ã,  if (GetViewportX() == 0) SetViewport (768, GetViewportY());
}
Ã, 
if (mouse.x > 380) {
Ã,  if (GetViewportX() < 768) SetViewport (GetViewportX() + 5, GetViewportY());
Ã,  if (GetViewportX() == 768) SetViewport (0, GetViewportY());
}

Hopefully, this'll scroll the screen in a nice, smooth loop (apart from any characters / objects in the overlap, which you'll have to double up). Works for me, anyway.

To scroll walking characters, I think you have to:
Ã,  Ã, 1. Set the screen transition to Instant (since you say this is probably going to be a 1 room game, just do it on the settings window).
Ã,  Ã, 2. Set the left screen edge to 200 pixels in, and make the interaction NewRoomEx (ROOM, 767, player.y);
Ã,  Ã, 3. Set the rightt screen edge to 768 pixels in, and make the interaction NewRoomEx (ROOM, 201, player.y);
HOWEVER, I'm not totally sure on this, so you might want to look this bit up somewhere else.
Title: Re: Edge scrolling...
Post by: Haddas on Thu 01/07/2004 10:07:04
I don't think the characters will cause problems, because it's in first person...

Damn my stupidity, I'm never gonna get anything to work >:(. I did everything I could, but I just can't get it to work... I'm thinking I'll drop this until I get better at scripting (like that's ever gonna happen).
Title: Re: Edge scrolling...
Post by: Ashen on Thu 01/07/2004 18:05:57
Why is it not working? Or, rather, HOW, is it not working? What is happening, what isn't happening?

The scripting I gave you works fine for me, I'm confused that it doesn't for you.

EDIT:
Link deleted
Title: Re: Edge scrolling...
Post by: Haddas on Thu 01/07/2004 19:21:21
thanks. I'll try that :D

Now if only it wouldn't lead me too a "oops, file not found" page...

I greatly appreciate your help.
Title: Re: Edge scrolling...
Post by: Ashen on Thu 01/07/2004 20:13:06
Danged GeoCities. Try this one:
http://www.geocities.com/WhoIsMonkey/Scroller.zip
(Right Click, and 'Save Target As...')
Title: Re: Edge scrolling...
Post by: faizin on Wed 25/05/2005 13:58:36
I getting confusing...is this 360 degree camera......??? :o
Title: Re: Edge scrolling...
Post by: Ishmael on Wed 25/05/2005 14:05:35
Quote from: faizin on Wed 25/05/2005 13:58:36
I getting confusing...is this 360 degree camera......??? :o

Depends on what you mean by "360 degree camera". If you're after a camera that orbits a single point always focused to the point, this isn't the droid you are looking for, but if you mean a static position camera that rotates and shows everthing around it, this is.

The looping room in the demo game should cover the very same subject, though in a bit diffrent way. But the idea is the same, apart from the scrolling...