On 07/06/2011 10:44 AM, James Paige wrote:
Well, solved in the sense that I can add six more rows and 10 more
columns to my background layer and it will look okay, but I still really
want to understand the math needed to make the parallax work with the
1/3 size layer, since that is the same math that will be required when
parallax scrolling is a built-in feature on different-sized map layers
in the future.
First, let us suppose a few things:
MapWidth := 3000
LayerWidth := 1000
ScreenWidth := 320
You want the layer to butt up against the left side of the map when the
camera is at X = 0, and to butt up against the right side of the map
when the camera is as X = (MapWidth - ScreenWidth).
When on the left side of the map, the camera's X, the map's X and the
layer's X are all 0. This case is easy.
On the right side of the map, however, it's not so easy. The camera stop
at 2680 (MapWidth - ScreenWidth), while the layer needs to stop at 2000
(MapWidth - LayerWidth).
To get a smooth interpolation, you simply need to map the camera's X%
(defined as "CameraX / (MapWidth - ScreenWidth)") to the layer's X%
(defined as "LayerX / (MapWidth - LayerWidth)").
This formula is most easily expressed as:
LayerX = (CameraX / (MapWidth - ScreenWidth)) * (MapWidth - LayerWidth)
We know that when the CameraX% is 50% (1340), the LayerX should be at
1000. Let's verify that:
LayerX = (1340 / (3000 - 320)) * (3000 - 1000)
LayerX = (1340 / 2680) * 2000
LayerX = 0.5 * 2000
LayerX = 1000
I can't seem to find the original email in which I presume you listed
the script, but if you plug that formula in, it should work.
--
- Mike Caron
_______________________________________________
Ohrrpgce mailing list
ohrrpgce@lists.motherhamster.org
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org