Cauldron2D.GameMaker.Draw (Cauldron2D.GameMaker v0.2.1)

Copy Markdown View Source

A running game's frame as a Cauldron2D.DrawList, in room pixels.

{world, items} = Cauldron2D.GameMaker.Draw.run(world)
{world, gui} = Cauldron2D.GameMaker.Draw.gui(world)

run/1 gives the room's own pictures — GameMaker Studio 1 backgrounds and tiles, or GameMaker Studio 2 background, tile and asset layers — every visible instance, and the particles (Cauldron2D.GameMaker.Particles). An instance whose object has code for the draw event runs it, and that code adds what it draws with sprite/4, rectangle/4, text/5 and item/2; any other instance is drawn as its sprite at its frame, scale, angle, blend and alpha. Instances of equal depth draw newest first, so the one made earliest is in front, as the runtime keeps each new instance at the head of its depth's list; and at equal depth, the instances a GameMaker Studio 2 room placed on its own layer (room_layer) are in front of those code made, which the runtime keeps on a layer of its own. gui/1 runs the draw GUI events the same way, for items in window pixels.

Items name their pictures as Cauldron2D.GameMaker.Pictures.table/2 keys them: {:sprite, sprite, frame}, {:background, background}, {:tile, background, tile}, {:tile, background, {x, y, width, height}}, {:sprite_part, sprite, {x, y, width, height}}, {:glyph, font, character} and :pixel, a single white pixel scaled and blended into a filled rectangle. A room layer's tiles are one item, {:tile_layer, room, layer, blend} (Cauldron2D.GameMaker.TileLayers, whose raster/3 draws it). A tile added by code (World.add_tile/5) is {:part, {:sprite, sprite, 0}, {x, y, width, height}}: that part of the picture {:sprite, sprite, 0} names (Cauldron2D.GameMaker.Surfaces.lookup/2 cuts it).

Summary

Functions

The background colour the room clears to, {r, g, b, a}.

The world after its draw GUI events, and what they drew.

From draw code: the world with item, any Cauldron2D.DrawList item, drawn — a picture the game names itself, as its own picture table keys it. It takes the drawing instance's depth unless it has its own.

From draw code: the world with a line drawn (line_item/5).

The draw list item of a line width pixels wide from from to to in colour {r, g, b} (draw_line_width): a white pixel stretched along the line and turned to it. Options: :alpha, :depth. Usable on a surface (Cauldron2D.GameMaker.Surfaces.draw/3) as well as in a frame (item/2).

From draw code: the world with the rectangle {left, top, right, bottom} filled with colour {r, g, b}. Options: :alpha, :depth.

The world after its draw events, and the frame's draw list.

From draw code: the world with instance id drawn as GameMaker draws an instance with no draw event of its own (draw_self): its sprite's frame at image_index, scaled, turned, blended and faded as the instance is.

From draw code: the world with frame frame of sprite sprite drawn at {x, y}, at the drawing instance's depth unless :depth is given. Other options are those of a draw list item: :scale, :angle, :blend, :alpha.

From draw code: the world with string drawn in font at {x, y}, laid out and styled by Cauldron2D.GameMaker.Text.items/5 with opts.

Functions

background(world)

@spec background(Cauldron2D.GameMaker.World.t()) :: {byte(), byte(), byte(), byte()}

The background colour the room clears to, {r, g, b, a}.

gui(world)

The world after its draw GUI events, and what they drew.

item(world, item)

From draw code: the world with item, any Cauldron2D.DrawList item, drawn — a picture the game names itself, as its own picture table keys it. It takes the drawing instance's depth unless it has its own.

line(world, from, to, width, colour, opts \\ [])

From draw code: the world with a line drawn (line_item/5).

line_item(arg1, arg2, width, colour, opts \\ [])

@spec line_item(
  {number(), number()},
  {number(), number()},
  number(),
  {byte(), byte(), byte()},
  keyword()
) :: map()

The draw list item of a line width pixels wide from from to to in colour {r, g, b} (draw_line_width): a white pixel stretched along the line and turned to it. Options: :alpha, :depth. Usable on a surface (Cauldron2D.GameMaker.Surfaces.draw/3) as well as in a frame (item/2).

rectangle(world, arg, colour, opts \\ [])

From draw code: the world with the rectangle {left, top, right, bottom} filled with colour {r, g, b}. Options: :alpha, :depth.

run(world)

The world after its draw events, and the frame's draw list.

self(world, id)

From draw code: the world with instance id drawn as GameMaker draws an instance with no draw event of its own (draw_self): its sprite's frame at image_index, scaled, turned, blended and faded as the instance is.

sprite(world, sprite, frame, position, opts \\ [])

From draw code: the world with frame frame of sprite sprite drawn at {x, y}, at the drawing instance's depth unless :depth is given. Other options are those of a draw list item: :scale, :angle, :blend, :alpha.

text(world, font, string, position, opts \\ [])

From draw code: the world with string drawn in font at {x, y}, laid out and styled by Cauldron2D.GameMaker.Text.items/5 with opts.