Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 29/05/2006 00:11:00

Title: Stagnet backdrop with scrolling forground logic
Post by: on Mon 29/05/2006 00:11:00
I'm creating an game with ags, and I was wondering exactly how I would place a 320x200 background to stand still while the character moves left and right and the hall he is in scrolls with the character.

For example: My character walks to the right. The background will be a image of a sky with the sun that stays in one area and doesn't scroll with the character. While the sky stays the same, the sidewalk he is walking on scrolls along with him.

I can't seem to find where to even start with the logic. Any help would be appreciated! ???
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: Akumayo on Mon 29/05/2006 01:22:38
Well, you could make the sidewalk and the grass below it the background, and leave the space above the sidewalk white.Ã,  Then, make an object with the sky scene on it, and place that above the sidewalk to make the sky.Ã,  Then in the room's reapetedly_excecute:

oSkyObject.X = player.x;

This way, the sky should follow the player's x coordinate, making it appear static on the screen, while the background is really scrolling.Ã, 

Just in case it lags one pixel, you should make that white space I mentioned earlier the same color that the main sky is (blue, surely), that way it looks smooth as it follows the character.

That should work I think, I haven't tried it at all though.

-Regards, Akumayo
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: on Mon 29/05/2006 02:27:37
Quote from: "Nerezza Terra" Akumayo on Mon 29/05/2006 01:22:38
Well, you could make the sidewalk and the grass below it the background, and leave the space above the sidewalk white.  Then, make an object with the sky scene on it, and place that above the sidewalk to make the sky.  Then in the room's reapetedly_excecute:d

oSkyObject.X = player.x;

This way, the sky should follow the player's x coordinate, making it appear static on the screen, while the background is really scrolling. 

Just in case it lags one pixel, you should make that white space I mentioned earlier the same color that the main sky is (blue, surely), that way it looks smooth as it follows the character.

That should work I think, I haven't tried it at all though.

-Regards, Akumayo

I've placed the script under the reapetedly_excecute section and it works as it is told, but I also have the problem as to when you enter the room, the image that is insync to your character moves off center to the actual background. So if I spawn into the room from the far right, a portion of the left sky is blank untill my character center with the room. Also, you were right about the lag of the sky. It is about a pixel or two behind. (My brother and I call what Akumayo created a "dirty hack")

Anyone else have any ideas? Thank you in advance. :)
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: Khris on Mon 29/05/2006 02:33:10
You'd have to create a scrolling room by choosing e.g. a 960x200 picture as background.
Do as Akumayo said and leave the top blank, then use a 340-wide object with its baseline set to the very top of the screen for the sky.
But for obvious reasons, the object's x-coordinate needs to be set to the ViewportX, so the line of code has to be:
oSkyobject.X = GetViewportX()-10;
(I've added 10 pixels to the left and right.)

However, when I tested it, the scrolling wasn't smooth at all. The sun I've painted on the sky jumped a bit.

The reason: The character's coordinates don't change smoothly, they increase in steps as big as the character's speed setting. Even after setting the speed to 1, though, the sun was still jumping slightly.

A workaround could be to use custom walking code.

Here's the source, if you want to take a look at it: click (2.7) (http://www.2dadventure.com/ags/SkyScroller.zip)

EDIT:
A "dirty hack"? There isn't any other way.
And why the f did you quote the WHOLE GODDAMN post directly above yours...?
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: on Mon 29/05/2006 02:49:31
Quote from: KhrisMUC on Mon 29/05/2006 02:33:10
And why the f did you quote the WHOLE GODDAMN post directly above yours...?
Thank a bunch of that snippit of code. It is still lagging behind by one fram when you move left and right in the center of the room. But besides that... GENIUS! Thanks a bunch. If there is no fix for the frame laggage... no biggie if not. Thanks for your help!
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: SSH on Mon 29/05/2006 12:23:33
Assuming you're not in 256-colour mode, you could have that part of the background all magenta (R255, G0, B255) and then grab the section of screen as a Dynamic sprite, then put and overlay on top of the static background and another overlay on top of that that is the sprite you captured earlier (this ensures that anything on top of the background is still visible)...
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: GarageGothic on Mon 29/05/2006 13:42:05
You could also use SetViewPort command to create your own scroll function. That way you could update the scrolling and the object coordinates in-sync. Perhaps you could use some code from this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=25937.0
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: Wretched on Mon 29/05/2006 14:09:22
Here's my solution Backdrop Demo (2.71) (http://www.alpha72.com/CRS/Backdrop.zip)
Use an object as the backdrop with walk behinds to make it appear behind everything. Make the player character 100% transparent then add a dummy (non-clickable) character that is (in repeatedly_execute_always()) constantly updated with the player position, view, frame and loop etc. This dummy player removes the frame stutter from the actual player, in effect it will lag behind the invisible player by 1 frame but this is usually un-noticeable and removes all frame stutter problems. Interactions will still work on the player character even though you can't actually see it.
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: SSH on Tue 30/05/2006 16:58:40
I think there was a parallax scrolling plugin once, but I doubt that it works on the latest AGS...
Title: Re: Stagnet backdrop with scrolling forground logic
Post by: hedgefield on Tue 30/05/2006 18:11:35
Yeah, the plugin works great. Gilbot converted it to a module a while back. It's in early stages, so there's only parallax for objects in the foreground.

Link. (http://www.2dadventure.com/ags/parallax.zip)