Cauldron2D.Parallax.Layer (Cauldron2D v0.2.2)

Copy Markdown View Source

One depth of a parallax background.

Cauldron2D.Parallax.Layer.new(
  name: :mountains,
  cell: Cauldron2D.Parallax.Strip.cells(rows, wrap: :x),
  factor: {0.25, 0.1},
  drift: {-0.4, 0.0}
)

factor is the share of the camera's distance from origin the layer moves: 1.0 moves with the world, 0.0 is pinned, above 1.0 is nearer than the world. drift is tiles a second the layer moves on its own, through the same arithmetic as factor.

movers and volumes are in the layer's own tiles, either a list or a function of the layer's visible rectangle, {{origin_x, origin_y}, {columns, rows}}.

void decides what an empty tile is: :transparent lets the layers behind show through, :opaque fills with the atlas's void colour, which is what the backmost layer wants.

front: true puts the layer over the world rather than behind it. animated: true lets art with frames animate, redrawn fps times a second. cache: false redraws the layer every frame, which a layer whose movers move needs.

Summary

Functions

Where this layer is looked at from, for a world focus and a time in milliseconds.

The layer's movers for a visible rectangle.

A layer from opts, which must give :name and :cell.

The layer's volumes for a visible rectangle.

Types

mover()

@type mover() ::
  {term(), {number(), number()}} | {term(), {number(), number()}, number()}

pair()

@type pair() :: {float(), float()}

rect()

@type rect() :: {{integer(), integer()}, {pos_integer(), pos_integer()}}

t()

@type t() :: %Cauldron2D.Parallax.Layer{
  animated: boolean(),
  bands: Cauldron2D.Parallax.Bands.t() | nil,
  cache: boolean(),
  cell: ({integer(), integer()} -> term()),
  drift: pair(),
  factor: pair(),
  fps: pos_integer(),
  front: boolean(),
  movers: [mover()] | (rect() -> [mover()]),
  name: atom(),
  origin: pair(),
  picture: map() | nil,
  void: :transparent | :opaque,
  volumes: list() | (rect() -> list())
}

Functions

focus(layer, arg, at)

@spec focus(t(), {number(), number()}, number()) :: pair()

Where this layer is looked at from, for a world focus and a time in milliseconds.

movers(layer, rect)

@spec movers(t(), rect()) :: [mover()]

The layer's movers for a visible rectangle.

new(opts)

@spec new(keyword()) :: t()

A layer from opts, which must give :name and :cell.

volumes(layer, rect)

@spec volumes(t(), rect()) :: list()

The layer's volumes for a visible rectangle.