Hey, so I'm making this game that has large background maps, for example: 2000 x 1187 while playing at 1024 x 768 resolution. What I want is to be able to lock the screen on the X axis, but still have it be able to scroll on the Y axis until the character goes down a certain number of stairs, then to have the X axis unlock in a non-jarring way (ReleasePort is kind of abrupt) as the character now begins to scroll to the right of the screen. Optional scrolling? I don't know what to call it, but I would really appreciate any help concerning it! Thanks for any thoughts.
I put together a module:
https://www.dropbox.com/s/v6i083q5ziulfon/SmoothScrolling0.1.scm
(right click the script node, click "Import script...", then select the file)
There already is a smooth scrolling module by Ali, but I was adding the whole lockX / lockY stuff and decided to write my own from scratch.
I did some basic testing, and it works fine so far.
All coordinates are center coordinates, not top-left corner coords like with AGS's SetViewport().
Commands:
SmoothScrolling.Activate(optional int speed); higher value = slower scrolling
SmoothScrolling.Deactivate(); return to standard AGS scrolling
SmoothScrolling.SetThreshold(optional int threshold); character can move x pixels from
center without scrolling
SmoothScrolling.LockX(optional int x); lock to current or specific x coordinate
(will scroll there non-blocking)
SmoothScrolling.LockY(optional int y); lock to current or specific y coordinate
(will scroll there non-blocking)
SmoothScrolling.LockXY(int x, int y); lock to specified coordinates (will scroll
there non-blocking)
pass -1 for x or y to use current coordinate
SmoothScrolling.UnlockX(); unlock one axis or both
SmoothScrolling.UnlockY();
SmoothScrolling.Unlock();
bool SmoothScrolling.IsXLocked(); returns whether axis is currently locked
bool SmoothScrolling.IsYLocked();
SmoothScrolling.Center(); replacement for ReleaseViewport(), instantly
center on player
(unlocks both axes, useful in first room's room_Load
to avoid initial arbitrary scrolling)
SmoothScrolling.SetXY(int x, int y); replacement for SetViewport(x, y)
Basic usage example (only necessary in first interactive room, not each room):
function room_Load()
{
SmoothScrolling.Center();
SmoothScrolling.SetThreshold(150);
SmoothScrolling.Activate();
}
(I'll properly release this after some testing. Maybe :))
Ah! So after some fiddling, I've figured it out, and this is beyond what I was looking for. THANK YOU SO MUCH. You are a king amongst men to go to these lengths for me (presuming you weren't already working on something similar). I'm making a surrealist game, so perspective control is everything, You really made my week, thank you :}
You're welcome :)
I hadn't coded in AGS for a while, and writing this took barely half an hour, so it was no big deal.