Gleam - v1.0.2
    Preparing search index...

    Class Particle

    Single particle drawn as a filled circle. The constructor seeds a random velocity (random angle, per-axis speed in [50, 150] px/s) and a random maxLifeTime in [0.5, 1.5] s — spawn many at once for spark/dust effects. Each tick update(dt) advances lifetime and pos; the particle is "dead" when alive flips to false.

    Index

    Constructors

    Properties

    _rect: Rect

    Backing storage for the rect getter. Subclasses can read it; the public-facing accessor is rect.

    color: string

    CSS color string passed to context.fillStyle in draw.

    lifetime: number = 0

    Accumulated time (seconds) since spawn or last resetLifetime.

    maxLifeTime: number

    Lifetime cap in seconds, randomized to [0.5, 1.5] at construction.

    pos: Vec2

    Top-left position. Cloned from the constructor arg so the caller's Vec2 isn't aliased.

    size: number

    Circle radius (pixels).

    vel: Vec2

    Velocity in px/s. Seeded randomly by the constructor (random angle, random magnitude per axis).

    Accessors

    Methods

    • Fill a circle at pos + offset using color. offset is useful for shifting by a camera/world transform without mutating pos.

      Parameters

      • context: CanvasRenderingContext2D
      • offset: Vec2 = ...

      Returns void

    • Recycle a dead particle by subtracting maxLifeTime from lifetime — preserves any overshoot so a pool of pre-allocated particles can stay phase-stable across loops. Note this doesn't re-randomize vel or pos; mutate those externally if you want a fresh trajectory.

      Returns void

    • Integrate lifetime, position, and bounding rect.

      Parameters

      • dt: number

      Returns void