Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Sat 17/07/2010 09:31:50

Title: Vertical Scrolling Room [SOLVED]
Post by: arj0n on Sat 17/07/2010 09:31:50
I'm trying to get a vertical scrolling room working.
Gameresolution: 640x480, room background resolution: 640x5421
Can't figure out why this piece of code doesn't work...:


function room_RepExec()
{
if (mouse.y <= 20) { //if mouse is near top of screen
 SetViewport (GetViewportY() - 10, GetViewportX()); // scroll down 10 pixels. Change this for quicker or slower scrolling.
}
else if (mouse.y >= 300) { //if mouse is bottom of screen
SetViewport (GetViewportY() + 10, GetViewportX()); // scroll up 10 pixels. Change this for quicker or slower scrolling.
}
}
Title: Re: Vertical Scrolling Room
Post by: GarageGothic on Sat 17/07/2010 09:37:57
You're ADDING ten pixels in both cases. Obviously the first case should subtract them. Also you will need to check that you're not setting the Viewport out of the room bounds.

Edit: Did you just edit the code? Or am I seeing things? Just realized, you've inverted the x,y coordinate order in SetViewport.
Title: Re: Vertical Scrolling Room
Post by: arj0n on Sat 17/07/2010 09:40:28
added this:
SetViewport (GetViewportY() + 10, GetViewportX()); // scroll down 10 pixels.
into:
SetViewport (GetViewportY() - 10, GetViewportX()); // scroll down 10 pixels.

I noticed it after submitting the post...
Title: Re: Vertical Scrolling Room
Post by: arj0n on Sat 17/07/2010 09:41:49
The problem is that it doesn't scroll at all ???
Title: Re: Vertical Scrolling Room
Post by: GarageGothic on Sat 17/07/2010 09:42:13
Made an edit of my own:

Quoteyou've inverted the x,y coordinate order in SetViewport
Title: Re: Vertical Scrolling Room
Post by: arj0n on Sat 17/07/2010 09:44:53
{
if (mouse.y <= 20) { //if mouse is near top of screen
  SetViewport (GetViewportX() - 10, GetViewportY()); // scroll down 10 pixels.
}
else if (mouse.y >= 300) { //if mouse is bottom of screen
SetViewport (GetViewportX() + 10, GetViewportY()); // scroll up 10 pixels.
}
}

Having this, still nothing happens.
Title: Re: Vertical Scrolling Room
Post by: GarageGothic on Sat 17/07/2010 09:46:52
Dude, you still need to add/subtract the pixels from the y coordinate (vertical), not the x (horizontal)
Title: Re: Vertical Scrolling Room
Post by: arj0n on Sat 17/07/2010 09:55:22
I'm sorry but I don't understand it.

Tried this
SetViewport (GetViewportX() - 10, GetViewportY()); // scroll down 10 pixels.
and this
SetViewport (GetViewportY() - 10, GetViewportX()); // scroll down 10 pixels.

both do nothing...
Title: Re: Vertical Scrolling Room
Post by: GarageGothic on Sat 17/07/2010 10:01:43
SetViewport (GetViewportX(), GetViewportY()-10);

That's scroll UP 10 pixels, btw.
Title: Re: Vertical Scrolling Room [SOLVED]
Post by: arj0n on Sat 17/07/2010 10:08:29
OK, got it. Thanx!
Title: Re: Vertical Scrolling Room [SOLVED]
Post by: Khris on Sat 17/07/2010 11:50:14
Wow. ;D
Title: Re: Vertical Scrolling Room [SOLVED]
Post by: arj0n on Sat 17/07/2010 12:32:18
Yeh sorry, I know... ;)

Somehow I thought I needed to switch GetViewportX() & GetViewportY()
in stead switching the number of pixels from X to Y...
Anyway...
Title: Re: Vertical Scrolling Room [SOLVED]
Post by: Matti on Sat 17/07/2010 13:20:47
;D

Sorry, but that's the funniest beginner's tech thread I've seen in a long long time.