Cauldron2D.GameMaker.Particles (Cauldron2D.GameMaker v0.2.1)

Copy Markdown View Source

Particles, as GameMaker's part_particles_create makes them: pictures that code sets loose, which move, animate and fade by themselves and are gone when their life runs out. They are drawn with the room, at their depth, and cleared when a room is entered.

world = Cauldron2D.GameMaker.Particles.create(world, %{
  sprite: flame, position: {x, y}, velocity: {0.0, -0.4}, life: 14, frame_speed: 0.5
})

A particle is a map:

  • :sprite — a sprite index; :frame the frame it starts on (default 0) and :frame_speed frames a step (default 0), wrapping. Or, in its place, :picture — any picture key of the draw list, such as :pixel, drawn from its top-left corner
  • :position (required) {x, y}; :velocity {x, y} pixels a step (default still); :gravity {x, y} added to the velocity every step (default none)
  • :life (required) — the steps it lasts
  • :alpha {from, to}, faded across its life (default {1.0, 1.0}); :blend {r, g, b}; :scale {x, y}; :depth (default 0)

Summary

Functions

The world with particle set loose.

The particles as draw list items, each naming {:sprite, sprite, frame} or its own picture.

The world with every particle one step on, and those whose life is over gone.

The particles for which pick is true, taken out of the world: {taken, world}. A particle keeps any keys of its own it was created with, so pick can tell kinds apart.

Types

particle()

@type particle() :: %{
  :position => {number(), number()},
  :life => pos_integer(),
  optional(atom()) => term()
}

Functions

create(world, particle)

The world with particle set loose.

items(world)

@spec items(Cauldron2D.GameMaker.World.t()) :: [map()]

The particles as draw list items, each naming {:sprite, sprite, frame} or its own picture.

step(world)

The world with every particle one step on, and those whose life is over gone.

take(world, pick)

The particles for which pick is true, taken out of the world: {taken, world}. A particle keeps any keys of its own it was created with, so pick can tell kinds apart.