Module parallax_layer
A single layer of a Parallax.
ParallaxLayer extends BoundObject
Properties
| p_factor | The proportion by which to scroll the x axis against
the camera.focal x position. |
| offset | An {x, y} vector of the layer's offset in pixels. |
| y_wiggle | The pixel range across which to translate the ParallaxLayer
against the camera.focal y position. |
| texture_size | (readonly) A {w, h} vector representing the size of the layer's
texture in pixels. |
| z | The ParallaxLayer's z value. |
Class Methods
| ParallaxLayer:new (image) | Create a new ParallaxLayer by loading an image. |
Instance Methods
| parallax_layer:p_cascade (top, bottom) | Create a linear p_factor interpolation across the height of the
ParallaxLayer. |
Properties
Properties. Significant fields on an instance.- p_factor
-
The proportion by which to scroll the
xaxis against the camera.focalxposition.A positive p_factor means that
ParallaxLayerwill scroll opposite theCamera(camera goes right, layer goes left). If abs(p_factor ) <1, it will scroll slower than the camera. Usually a positive p_factor between0and1is what you want. - offset
-
An
{x, y}vector of the layer's offset in pixels.{0, 0}aligns the top edge of the layer with the sea_level. Theyoffset is arguably more useful thanx. Thexvalue simply changes the phase of thexrepeat.Warning: You must set the property explicitly for changes to take apply. Like this:
layer.offset = {10, 11}Not this:
layer.offset[2] = 11 - y_wiggle
-
The pixel range across which to translate the
ParallaxLayeragainst the camera.focalyposition.A positive y_wiggle means that
ParallaxLayerwill translate opposite theCamera(camera goes down, parallax goes up). Can be positive or negative.The parent parallax.y_wiggle combines with this one.
Default
0 - texture_size
-
(readonly) A
{w, h}vector representing the size of the layer's texture in pixels. - z
-
The
ParallaxLayer's z value.Default
-180.0
Class Methods
Class Methods. Must be called onClass, with a capital leading character.
e.g. Class:method("foo")
- ParallaxLayer:new (image)
-
Create a new
ParallaxLayerby loading an image.Parameters:
- image string The file name of the image to load.
Returns:
-
ParallaxLayer
Instance Methods
Instance Methods. Must be called on an instance ofClass.
e.g. instance:method("foo")
- parallax_layer:p_cascade (top, bottom)
-
Create a linear p_factor interpolation across the height of the
ParallaxLayer.This allows fine-grained control over a layer's parallax behavior with a simple interface. First,
p_cascadewill set the p_factor of the layer to be MAX(top,bottom). Then it will interpolate between the two values and set a parallax factor for each row of pixels in the layer's texture.Parameters:
- top number The p_factor for the top row of layer's pixels
- bottom number The p_factor for the bottom row of layer's pixels