Cauldron2D.GameMaker.Surfaces (Cauldron2D.GameMaker v0.2.1)

Copy Markdown View Source

Surfaces, as GameMaker's surface_* functions make them: rasters code draws onto, kept in the world by id until freed, across rooms.

{world, canvas} = Surfaces.create(world, 320, 200)
world = Surfaces.draw(world, canvas, [%{picture: {:sprite, 3, 0}, position: {10, 10}}])
world = Draw.item(world, Surfaces.item(world, canvas, {x, y}))

Drawing onto a surface renders at once, as surface_set_target does: draw/3 takes draw list items in the surface's own pixels and draws them over what is there, with the world's pictures lookup, and {:surface, id} naming another surface, each blended as GameMaker blends onto a surface — its blend factors applied to the alpha channel as well as the colours (Cauldron2D.Blend's {:gamemaker, mode}). item/4 is a draw list item showing a surface; a frame shows it by looking {:surface, id} up in the world's surfaces (lookup/2). draw/4 takes :write, the channels drawing may change, as draw_set_colour_write_enable sets them.

lookup/2 also gives Cauldron2D.GameMaker.Shapes' pictures, such as {:ellipse, {width, height}, :filled}, and a tile layer's picture (Cauldron2D.GameMaker.TileLayers).

Summary

Functions

The world with surface id filled with colour {r, g, b} at alpha (draw_clear_alpha).

The world with surface source's pixels put on surface destination with their top-left corner at {x, y}, replacing what was there, colour and alpha alike (surface_copy(destination, x, y, source)); what falls outside destination is left out.

The world with a new surface width × height, clear; {world, id}.

The world with items, in surface id's pixels, drawn over surface id. Option :write {red, green, blue, alpha}, each true or false, names the channels the drawing changes; the others keep what the surface held (draw_set_colour_write_enable). Default: all four.

Whether surface id exists.

The world without surface id.

A draw list item showing surface id with its top-left corner at {x, y}. Options: those of a draw list item (:scale, :angle, :blend, :alpha, :mode, :depth) and :origin.

The raster for draw list picture key: a surface of the world's or part of one, a shape, or the world's own pictures.

A draw list item showing the part {left, top, width, height} of surface id, its top-left corner at {x, y} (draw_surface_part_ext): the part is clipped to the surface, and what is clipped from its left and top moves the corner by as much, scaled. Options as item/4's. nil when nothing of the part lies on the surface.

Every surface's raster, by id.

Surface id's size {width, height}.

Types

id()

@type id() :: non_neg_integer()

Functions

clear(world, id, arg, alpha)

The world with surface id filled with colour {r, g, b} at alpha (draw_clear_alpha).

copy(world, destination, arg, source)

The world with surface source's pixels put on surface destination with their top-left corner at {x, y}, replacing what was there, colour and alpha alike (surface_copy(destination, x, y, source)); what falls outside destination is left out.

create(world, width, height)

The world with a new surface width × height, clear; {world, id}.

draw(world, id, items, opts \\ [])

The world with items, in surface id's pixels, drawn over surface id. Option :write {red, green, blue, alpha}, each true or false, names the channels the drawing changes; the others keep what the surface held (draw_set_colour_write_enable). Default: all four.

exists?(world, id)

@spec exists?(Cauldron2D.GameMaker.World.t(), id() | nil) :: boolean()

Whether surface id exists.

free(world, id)

The world without surface id.

item(world, id, position, opts \\ [])

@spec item(Cauldron2D.GameMaker.World.t(), id(), {number(), number()}, keyword()) ::
  map()

A draw list item showing surface id with its top-left corner at {x, y}. Options: those of a draw list item (:scale, :angle, :blend, :alpha, :mode, :depth) and :origin.

lookup(world, shape)

The raster for draw list picture key: a surface of the world's or part of one, a shape, or the world's own pictures.

part_item(world, id, arg1, arg2, opts \\ [])

@spec part_item(
  Cauldron2D.GameMaker.World.t(),
  id(),
  {number(), number(), number(), number()},
  {number(), number()},
  keyword()
) :: map() | nil

A draw list item showing the part {left, top, width, height} of surface id, its top-left corner at {x, y} (draw_surface_part_ext): the part is clipped to the surface, and what is clipped from its left and top moves the corner by as much, scaled. Options as item/4's. nil when nothing of the part lies on the surface.

rasters(world)

@spec rasters(Cauldron2D.GameMaker.World.t()) :: %{
  required(id()) => FrenchCurve.Raster.t()
}

Every surface's raster, by id.

size(world, id)

Surface id's size {width, height}.