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 x axis against the camera.focal x position.

A positive p_factor means that ParallaxLayer will scroll opposite the Camera (camera goes right, layer goes left). If abs(p_factor ) < 1, it will scroll slower than the camera. Usually a positive p_factor between 0 and 1 is 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. The y offset is arguably more useful than x. The x value simply changes the phase of the x repeat.

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 ParallaxLayer against the camera.focal y position.

A positive y_wiggle means that ParallaxLayer will translate opposite the Camera (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 on Class, with a capital leading character. e.g. Class:method("foo")
ParallaxLayer:new (image)
Create a new ParallaxLayer by 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 of Class. 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_cascade will 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
generated by LDoc 1.3.12