Parallax scrolling scripts

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Parallax scrolling scripts

Post by Foxley »

Hey, I was just wondering if anyone has had any luck getting parallax scrolling scripts working better than the Troll Mountain example script. I'm thinking of incorporating it into my game for some maps, but the jerkiness is kind of visually offputting, especially when the player character stops movement.
User avatar
Pepsi Ranger
Liquid Metal Slime
Posts: 1457
Joined: Thu Nov 22, 2007 6:25 am
Location: South Florida

Post by Pepsi Ranger »

Not really. I've experimented with the numbers a bit, and even though horizontal parallax works okay, vertical parallax seems a bit jerkier. It may have to do with the dimensions of the map; I'm not sure.

Here's the script James offered me some time ago, with some modifications to the numbers to better suit my specific needs. You can try to do the same if you want (you'll want to use different script and variable names, of course):

Code: Select all

script,parallax balcony,begin
check mayor parallax
end

script,check mayor parallax,begin
if &#40;current map<>103&#41; then&#40;
stop timer &#40;35&#41;
sl &#58;= lookup slice&#40;sl&#58;map layer 0&#41;
    set slice x&#40;sl, 0&#41;
    set slice y&#40;sl, 0&#41;
exit script
&#41;
variable &#40;sl,mapw,maph,screenw,screenh,layerw,layerh&#41;
  mapw &#58;= map width * 20
  maph &#58;= map height * 20
  screenw &#58;= slice width&#40;sprite layer&#41;
  screenh &#58;= slice height&#40;sprite layer&#41;
  layerw &#58;= &#40;mapw / 2&#41; + &#40;mapw / 4&#41;
  layerh &#58;= maph / 2
  sl &#58;= lookup slice&#40;sl&#58;map layer 0&#41;
  set slice x&#40;sl, &#40;camera pixel x  * &#40;mapw -- layerw&#41; / &#40;mapw -- screenw&#41;&#41;&#41;
  set slice y&#40;sl, &#40;camera pixel y  * &#40;maph -- layerh&#41; / &#40;maph -- screenh&#41;&#41;&#41;
  set timer &#40;35,0,1,@check mayor parallax&#41;
end
The end result looks like this:

<object width="640" height="480"><param name="movie" value="http://www.youtube.com/v/0HolTv6PSaU?ve ... ram><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/0HolTv6PSaU?version=3&hl=en_US" type="application/x-shockwave-flash" width="640" height="480" allowscriptaccess="always" allowfullscreen="true"></embed></object>

As you can see, it's passable, but not at all perfect. This was the best I could get it without sending the background off the map.

If you want to see it from Custom's point of view so the numbers make sense:

<object width="640" height="480"><param name="movie" value="http://www.youtube.com/v/OrXCZUxzQmw?ve ... ram><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/OrXCZUxzQmw?version=3&hl=en_US" type="application/x-shockwave-flash" width="640" height="480" allowscriptaccess="always" allowfullscreen="true"></embed></object>
Place Obligatory Signature Here
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

I think that horizontal parallax looks pretty seamless. I guess it's just the vertical parallax that's the issue I'm assuming.

What was suggested to me once was doing this with slices (I haven't attempted this yet but think it should be fairly easy if you are familiar with slices). The way to do this is to first draw your map tiles on a higher map layer (like map layer 2). Then import the images you want to use for your parallax in the form of backdrops. Make a slice collection with the backdrops. Make a code that arranges the backdrops on the map so they all connect in to one large image. Parent these backdrop slices to a lower map layer (like layer 1), now the backdrops appear beneath the map tiles. Then make a mapautorun while loop code that checks your hero pixel (x,y) position and either re-draws the backdrops as the hero (x,y) changes, or moves the already drawn slices as the hero (x,y) changes. You can then adjust the mathematical relationship between the hero (x,y) and the position of the backdrop slices so that a change of +1 hero pixel equals a change of -3 slice pixels or whatever you want. You could even make the relationship anisotropic so horizontal parallax rate is different than vertical parallax rate. Or you could do other crazy stuff like specify if you only want one-directional parallax, diagonal parallax, sinusoidal parallax (would be neat if the characters on a cruise ship or something), basically anything you can think of. Hope that helps. If you need the code for drawing the backdrops to a map layer then I can supply it, but it assumes you know how to set things up in the slice editor and do slice related coding stuff...
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

sheamkennedy: using backdrop slices makes no difference over using tiles. It's just a way to get around the limited tileset size. Also, I've got to disagree that the horizontal parallax in that clip is fine; I think it's pretty horrible.

I wrote this script largely because of the problem with parallax:
http://rpg.hamsterrepublic.com/ohrrpgce ... _will_move
however I've only just put together a version of the parallax script that doesn't suffer from the jerkiness. Get it here:
http://rpg.hamsterrepublic.com/ohrrpgce ... e_Parallax
I've tested it and it now scrolls smoothly. It's not perfect though, there's over a dozen ways to make it glitch.

As for a REAL solution to this problem, it involves implementing a type of script which runs at the end of a tick rather than the start of a tick. I had hoped to implement them soonish; currently I'm planning to so soon after the release of Callipygous (don't want to destabilise things).
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

OK, it was pointed out to me that my scripts didn't work near the map edges. I've had to change the approach, so forget what you read on the Fake Parallax page previously, and look again.

Definitely wouldn't have written these scripts if I'd known it would be that much trouble.

Also, it occurred to me that if you use backdrops instead of a map layer as sheamkennedy suggested, then you could actually place the backdrops completely underneath the map, and mark map layer 0 as invisible. In that case you can actually do parallax in a far simpler way. There will still be a 1 tick lag as you move about, but it probably wouldn't be very noticeable because it wouldn't cause jerking of the parallax layer.
Last edited by TMC on Sat Feb 21, 2015 7:41 am, edited 1 time in total.
Post Reply