Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: SilverSpook on Wed 29/04/2015 13:03:14

Title: Simple Parallax Background
Post by: SilverSpook on Wed 29/04/2015 13:03:14
Is there a way to just have an object frozen in the background (for example a distant mountain)?  Basically, I want the object to never move in the player's screen, even when the rest of the room scrolls left and right.  I saw the parallax module but I was wondering if there was some simpler way to keep an object frozen in place. 

Thanks
Title: Re: Simple Parallax Background
Post by: Crimson Wizard on Wed 29/04/2015 14:46:24
Easy:
Code (ags) Select

function repeatedly_execute_always()
{
   oObj.X = GetViewportX();
   oObj.Y = GetViewportY();
}
Title: Re: Simple Parallax Background
Post by: SilverSpook on Wed 29/04/2015 22:28:19
Thanks!

One thing though: it seems when the view scrolls, the unmoving object is always one frame behind everything else?  So when the player starts / stops, the background lags a little bit, then jerks into place.  Is there a way to smooth the transition out so you don't get the jerking?  Right now I have "repeatedly_execute_always" in the room's script.
Title: Re: Simple Parallax Background
Post by: Ali on Thu 30/04/2015 09:01:39
If I recall correctly,  that jerkiness is inevitable unless you use DX9.
Title: Re: Simple Parallax Background
Post by: Monsieur OUXX on Thu 30/04/2015 09:07:05
Quote from: SilverSpook on Wed 29/04/2015 22:28:19
One thing though: it seems when the view scrolls, the unmoving object is always one frame behind everything else?

I'm not expert enough to tell the reason for sure, but I know that what you say is plausible, because when you update obj.X (resp. Y) you do it during your game cycle, whereas Viewport's X (resp. Y) was given to you from the previous game cycle.
I can't think of a solution from the top of my head, so I'll just say that you should use the SmoothScrolling module, which also allows parallax.

BOOM: just when I mention smoothscrolling, Ali pops in.

EDIT: if the jerkiness is inevitable, then another workaround would be not to do a perfectly still background, but instead a background that has a very slight scrolling/parallax effect. This way, nobody will notice.

Title: Re: Simple Parallax Background
Post by: Crimson Wizard on Thu 30/04/2015 09:21:37
Which version of AGS are you using?
I made this experimental engine version for Snarky, it's based on AGS 3.3.3 and supports "late_repeatedly_execute_always()" function that is run after new game state is calculated.
http://www.mediafire.com/download/jd86vdw6jxr6n5y/acwin_3.3.3--laterepexec.zip
Title: Re: Simple Parallax Background
Post by: Monsieur OUXX on Thu 30/04/2015 12:39:04
Quote from: Crimson Wizard on Thu 30/04/2015 09:21:37
late_repeatedly_execute_always()

Oh boy oh boy oh boy. I didn't know the existence of this. I'm excited.
Title: Re: Simple Parallax Background
Post by: SilverSpook on Thu 30/04/2015 20:24:29
I'm using AGS 3.4 unfortunately.  I need the free aspect ratio feature cause I'm working in 1366 x 768

Thanks for the support though!
Title: Re: Simple Parallax Background
Post by: Snarky on Thu 30/04/2015 20:50:47
If you script the room scrolling yourself instead of relying on the built-in one, it will all happen in user-script and should sync up correctly.
Title: Re: Simple Parallax Background
Post by: SilverSpook on Thu 30/04/2015 21:36:19
Hm, how would you disable the scrolling so to script it yourself?
Title: Re: Simple Parallax Background
Post by: Snarky on Fri 01/05/2015 01:08:48
The function is called setviewport or lockviewport or something like that. Search the manual for "viewport" and you should find it.