Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: robotronic on Fri 06/05/2011 19:51:19

Title: Looped background parallax
Post by: robotronic on Fri 06/05/2011 19:51:19
Hello,

Looking for a push in the right direction. My goal is to have a room on a moving train with the background looping. So it will take place in a train car, the outside scene will be scrolling past the windows. I have checked out the parallax plugin and I am not sure if this is the plug in I need.

So here is a break down of what I am trying to do:

Background image layer 2000px width - Trees and such looping infinitely at a set rate of speed.

Foreground image layer, 750px width - train car with transparent windows and outside the car. This will be the room the player is in.

Game window 800px width.

Hope this makes sense. I've searched the forums for clues as to how to accomplish this with no luck. It is quite possible I have no idea what I'm looking for. Any help is greatly appreciated.

Here is a link to the train car art:  Keep in mind the art is not finished.
(http://i.imgur.com/sZeeZ.jpg)
Title: Re: Looped background parallax
Post by: Vince Twelve on Fri 06/05/2011 20:43:55
I have a room very much like this in my game.  The way I did it was to make the train an object with baseline 2.  Then you have an object for the background with baseline 1.  You will put code into repeatedly_execute_always that moves the background object across the screen.  Two ways to handle the looping:

a) have two background objects one next to the other with the same image.  When one gets all the way across the screen, it moves automatically to the other side of it's partner.  So if they're scrolling to the left, the code would be something to the effect of.

(in room load)

oBackground1.x=0;
oBackground2.x=widthofbackgroundsprite;

(in rep_ex_always)

oBackground1.x=oBackground1.x-speed;
oBackground2.x=oBackground2.x-speed;

if(oBackground1.x<=-widthofbackgroundsprite) oBackground1.x=oBackground2.x+widthofbackgroundsprite;
if(oBackground2.x<=-widthofbackgroundsprite) oBackground2.x=oBackground1.x+widthofbackgroundsprite;

b) Or, just have one background object, but copy the left-most 800 pixels of the image to the right, extending the sprite by the screen width.  Then when that object gets to x==-widthofbackgroundsprite+800, set x=0.

Hopefully that's a useful nudge.
Title: Re: Looped background parallax
Post by: robotronic on Fri 06/05/2011 20:50:32
Thank you so much! Now that I know it is possible I will begin the background image. Which game of yours has this effect? I would love to check it out!
Title: Re: Looped background parallax
Post by: Vince Twelve on Fri 06/05/2011 21:41:48
Resonance.  Not out yet!  But there's a screenshot of the scene here:

(http://xiigames.com/wp-content/uploads/2008/01/Res_Subway.png)

Obviously, you can't see the movement, but there's stuff going on out side the windows/doors, and you can walk up and down the train.

The train also pulls into stations and stops, doors open, people enter/exit, then it continues back into the loop, etc.  So you can definitely get this to do what you want.