Class Emitter

Represents an emitter object that spawns particles in a scene.

Hierarchy (view full)

Constructors

Properties

active: boolean = true

Whether the object is active and should be updated

angle: number = 0

The angle to emit the particles.

angleDamping: number = 1

How much to dampen particle angular speed.

angleVelocity: number = 0

The object's angular velocity

animation?: Animation

The animation of the object sprite.

bounded: boolean = false

Whether the object is bounded by the scene and cannot move outside.

collideObjects: boolean = false

Whether particles collide against objects.

collideTiles: boolean = false

Whether particles collide against tiles.

color?: Color

The color of the object (if no sprite).

colorEnd: Color = ...

The color at the end of the particle's life. It is randomized between end colors.

colorStart: Color = ...

The color at the start of the particle's life. It is randomized between start colors.

damping: number = 1

How much to dampen particle speed.

dead: boolean = false

Whether the object is dead and should be removed

elasticity: number = 0

The object's elasticity (0-1)

emitConeAngle: number = Math.PI

The local angle to apply velocity to particles from the emitter.

emitRate: number = 100

How many particles per second to spawn. If set to 0, no particles will be emitted.

emitSize: number | Vector

The size of the emitter. It can be a float for circle diameter or a vec2 for rectangle dimensions.

emitTime: number = 0

How long the emitter stays alive (0 is forever).

fadeRate: number = 0.1

How quickly particles fade in at the start/end in percent of life.

family?: string

The family of the object.

flipH: boolean = false

Whether the object is flipped horizontally (mirrored)

flipV: boolean = false

Whether the object is flipped vertically

force: Vector = ...

The force applied to the object (acceleration)

friction: number = 0.8

The object's friction (0-1)

gid?: number

The global ID of the object image from TMX map (if any).

gravityScale: number = 0

How much gravity affects particles.

id: number = ...

The ID of the object.

image?: string

The image of the object (if any).

lastPos: Vector = ...

Last position of the object

layerId?: number

The layer ID of the object (if any).

mass: number = 1

The object's mass (0 is static)

maxSpeed: number = 1

Maximum speed

name?: string

The name of the object.

Additional properties for the emitter.

onGround: boolean | Entity = false

The object the entity is standing on

particleConeAngle: number = Math.PI

The cone for the start particle angle.

pos: Vector

The position of the emitter.

properties: Record<string, any> = {}

Custom properties of the object

randomness: number = 0.2

The randomness percent.

renderOrder: number = 0

The render order of particles.

scene: Scene

The scene the emitter belongs to.

shape: Shape = Shape.Rectangle

The shape of the particle.

size: Vector = ...

The size of the object (scaled by tileSize)

sizeEnd: number = 1

The size of particles at the end.

sizeStart: number = 0.1

The size of particles at the start.

solid: boolean = true

Whether the object is solid and collides with other objects

spawnTime: number = 0

Time the entity was spawned

speed: number = 0.1

The speed of particles when spawned.

sprite: Sprite = ...

The sprite of the object.

Sprite

stretchScale: number = 0

If set, the particle is drawn as a trail, stretched in the direction of velocity.

timeBuffer: number = 0

Time buffer for emit rate.

ttl: number = 0.5

How long particles live.

type: string = 'Platfuse.Emitter'

The type of the emitter.

visible: boolean = true

Whether the object is visible and should be drawn

Methods

  • Checks if the entity collides with a tile.

    Parameters

    • tileId: number

      The ID of the tile to check collision with.

    • pos: Vector

      The position of the entity.

    Returns boolean

    True if the entity collides with the tile, false otherwise.

  • Checks if the entity collides with a tile using raycasting.

    Parameters

    • tileId: number

      The data of the tile to check collision with.

    • pos: Vector

      The position of the entity.

    Returns boolean

    True if the entity collides with the tile, false otherwise.

  • Gets the current animation frame of the entity. If the sprite is defined, it returns the animation frame of the sprite. Otherwise, it returns 0.

    Returns number

    The current animation frame.

  • Returns the relative bounding rectangle of the entity. The relative bounding rectangle is calculated by translating the entity's bounding rectangle and moving it based on the position of the scene's camera.

    Returns Box

    The relative bounding rectangle of the entity.

  • Checks if the entity is overlapping with a given position and size.

    Parameters

    • pos: Vector

      The position vector of the other object.

    • size: Vector = ...

      The size vector of the other object.

    Returns boolean

    True if the entity is overlapping with the other object, false otherwise.

  • Randomizes the given value by applying randomness.

    Parameters

    • v: number

      The value to be randomized.

    Returns number

    The randomized value.

  • Sets the animation for the entity.

    Parameters

    • animation: Animation

      The animation to set.

    • flipH: boolean = false

      (Optional) Whether to flip the animation horizontally. Default is false.

    • flipV: boolean = false

      (Optional) Whether to flip the animation vertically. Default is false.

    Returns void

  • Updates the emitter.

    Returns void

    This method is responsible for updating the emitter's behavior, such as emitting particles based on the emit rate and time. If the emitter's alive time exceeds the emit time, the emitter is destroyed.