ParticleEmitter
Hierarchy
- Actor
- ParticleEmitter
Index
Constructors
Properties
- acceleration
- actions
- active
- beginColor
- body
- childrenAdded$
- childrenRemoved$
- collider
- componentAdded$
- componentRemoved$
- components
- deadParticles
- emitRate
- emitterType
- endColor
- endSize
- events
- fadeFlag
- focus
- focusAccel
- graphics
- id
- isEmitting
- logger
- maxAngle
- maxSize
- maxVel
- minAngle
- minSize
- minVel
- motion
- name
- numParticles
- particleLife
- particleRotationalVelocity
- particleTransform
- particles
- pointer
- radius
- random
- randomRotation
- scene
- startSize
- tagAdded$
- tagRemoved$
- transform
- defaults
Accessors
Methods
- addChild
- addComponent
- addTag
- addTemplate
- clearComponents
- clearParticles
- clone
- contains
- emit
- emitParticles
- get
- getAncestors
- getComponents
- getDescendants
- getGlobalPos
- getGlobalRotation
- getGlobalScale
- has
- hasAll
- hasAllTags
- hasTag
- isKilled
- kill
- off
- on
- onCollisionEnd
- onCollisionStart
- onInitialize
- onPostCollisionResolve
- onPostKill
- onPostUpdate
- onPreCollisionResolve
- onPreKill
- onPreUpdate
- once
- removeAllChildren
- removeChild
- removeComponent
- removeParticle
- removeTag
- unkill
- unparent
- update
- within
Constructors
constructor
Parameters
config: ParticleEmitterArgs
particle emitter options bag
Returns ParticleEmitter
Properties
publicacceleration
Gets or sets the acceleration vector for all particles
publicactions
Useful for quickly scripting actor behavior, like moving to a place, patrolling back and forth, blinking, etc.
Access to the Actor's built in [[ActionsComponent]] which forwards to the [[ActionContext|Action context]] of the actor.
publicactive
Whether this entity is active, if set to false it will be reclaimed
publicbeginColor
Gets or sets the beginning color of all particles
publicbody
The physics body the is associated with this actor. The body is the container for all physical properties, like position, velocity, acceleration, mass, inertia, etc.
publicchildrenAdded$
publicchildrenRemoved$
publiccollider
Access to the Actor's built in [[ColliderComponent]]
publiccomponentAdded$
publiccomponentRemoved$
publicreadonlycomponents
Current components on the entity
Do not modify
Use addComponent/removeComponent otherwise the ECS will not be notified of changes.
publicdeadParticles
Gets or sets the backing deadParticle collection
publicemitRate
Gets or sets the emission rate for particles (particles/sec)
publicemitterType
Gets or sets the emitter type for the particle emitter
publicendColor
Gets or sets the ending color of all particles
publicendSize
Gets or sets the optional ending size for the particles
publicevents
Listen to or emit events for an entity
publicfadeFlag
Gets or sets the fade flag which causes particles to gradually fade out over the course of their life.
publicfocus
Gets or sets the optional focus where all particles should accelerate towards
publicfocusAccel
Gets or sets the acceleration for focusing particles if a focus has been specified
publicgraphics
Access to the Actor's built in [[GraphicsComponent]]
publicid
The unique identifier for the entity
publicisEmitting
Gets or sets the isEmitting flag
publiclogger
Convenience reference to the global logger
publicmaxAngle
Gets or sets the maximum angle in radians
publicmaxSize
Gets or sets the maximum size of all particles
publicmaxVel
Gets or sets the maximum particle velocity
publicminAngle
Gets or sets the minimum angle in radians
publicminSize
Gets or sets the minimum size of all particles
publicminVel
Gets or sets the minimum particle velocity
publicmotion
Access the Actor's built in [[MotionComponent]]
publicname
publicnumParticles
publicparticleLife
Gets or sets the life of each particle in milliseconds
publicparticleRotationalVelocity
Gets or sets the particle rotational speed velocity
publicparticleTransform
Gets or sets the emitted particle transform style, [[ParticleTransform.Global]] is the default and emits particles as if they were world space objects, useful for most effects.
If set to [[ParticleTransform.Local]] particles are children of the emitter and move relative to the emitter as they would in a parent/child actor relationship.
publicparticles
Gets or sets the backing particle collection
publicpointer
Access to the Actor's built in [[PointerComponent]] config
publicradius
Gets or sets the emitter radius, only takes effect when the [[emitterType]] is [[EmitterType.Circle]]
publicrandom
Random number generator
publicrandomRotation
Indicates whether particles should start with a random rotation
publicscene
The current scene that the entity is in, if any
publicstartSize
Gets or sets the optional starting size for the particles
publictagAdded$
publictagRemoved$
publictransform
Access the Actor's built in [[TransformComponent]]
publicstaticdefaults
Accessors
publicacc
publicanchor
The anchor to apply all actor related transformations like rotation, translation, and scaling. By default the anchor is in the center of the actor. By default it is set to the center of the actor (.5, .5)
An anchor of (.5, .5) will ensure that drawings are centered.
Use
anchor.setTo
to set the anchor to a different point using values between 0 and 1. For example, anchoring to the top-left would beActor.anchor.setTo(0, 0)
and top-right would beActor.anchor.setTo(0, 1)
.Returns Vector
Parameters
vec: Vector
Returns void
publicangularVelocity
Gets the rotational velocity of the actor in radians/second
Returns number
Sets the rotational velocity of the actor in radians/sec
Parameters
angularVelocity: number
Returns void
publiccenter
Get the center point of an actor (global position)
Returns Vector
publicchildren
Get the direct children of this entity
Returns readonly Entity<any>[]
publiccolor
publicdraggable
Returns boolean
Parameters
isDraggable: boolean
Returns void
publicheight
Returns number
publicisInitialized
Gets whether the actor is Initialized
Returns boolean
publicisOffScreen
Indicates whether the actor is physically in the viewport
Returns boolean
publiclocalCenter
Get the local center point of an actor
Returns Vector
publicoffset
publicoldAcc
publicoldPos
publicoldVel
publicopacity
Gets the opacity of each particle from 0 to 1.0
Returns number
Gets the opacity of each particle from 0 to 1.0
Parameters
opacity: number
Returns void
publicparent
Returns Entity<any>
publicparticleSprite
publicpos
publicrotation
Gets the rotation of the actor in radians. 1 radian = 180/PI Degrees.
Returns number
Sets the rotation of the actor in radians. 1 radian = 180/PI Degrees.
Parameters
theAngle: number
Returns void
publicscale
publictags
Specifically get the tags on the entity from [[TagsComponent]]
Returns Set<string>
publictypes
The types of the components on the Entity
Returns ComponentCtor[]
publicvel
publicwidth
Returns number
publicz
Gets the z-index of an actor. The z-index determines the relative order an actor is drawn in. Actors with a higher z-index are drawn on top of actors with a lower z-index
Returns number
Sets the z-index of an actor and updates it in the drawing list for the scene. The z-index determines the relative order an actor is drawn in. Actors with a higher z-index are drawn on top of actors with a lower z-index
Parameters
newZ: number
new z-index to assign
Returns void
Methods
publicaddChild
publicaddComponent
publicaddTag
Adds a tag to an entity
Parameters
tag: string
Returns Entity<any>
publicaddTemplate
publicclearComponents
Returns void
publicclearParticles
Returns void
publicclone
Creates a deep copy of the entity and a copy of all its components
Returns Actor
publiccontains
Tests whether the x/y specified are contained in the actor
Parameters
x: number
X coordinate to test (in world coordinates)
y: number
Y coordinate to test (in world coordinates)
recurse: boolean = false
checks whether the x/y are contained in any child actors (if they exist).
Returns boolean
publicemit
Emits an event for target
Type parameters
- TEventName: EventKey<ActorEvents>
Parameters
eventName: TEventName
The name of the event to publish
event: ActorEvents[TEventName]
Optionally pass an event data object to the handler
Returns void
publicemitParticles
Causes the emitter to emit particles
Parameters
particleCount: number
Number of particles to emit right now
Returns void
get
Type parameters
- TComponent: Component
Parameters
type: ComponentCtor<TComponent>
Returns MaybeKnownComponent<TComponent, any>
publicgetAncestors
Returns a list of parent entities starting with the topmost parent. Includes the current entity.
Returns Entity<any>[]
publicgetComponents
Returns all component instances on entity
Returns Component[]
publicgetDescendants
Returns a list of all the entities that descend from this entity. Includes the current entity.
Returns Entity<any>[]
publicgetGlobalPos
Gets an actor's world position taking into account parent relationships, scaling, rotation, and translation
Returns Vector
Position in world coordinates
publicgetGlobalRotation
Gets this actor's rotation taking into account any parent relationships
Returns number
Rotation angle in radians
publicgetGlobalScale
Gets the global scale of the Actor
Returns Vector
publichas
Check if a component type exists
Type parameters
- TComponent: Component
Parameters
type: ComponentCtor<TComponent>
Returns boolean
hasAll
Verifies that an entity has all the required types
Type parameters
- TComponent: Component
Parameters
requiredTypes: ComponentCtor<TComponent>[]
Returns boolean
hasAllTags
Verifies that an entity has all the required tags
Parameters
requiredTags: string[]
Returns boolean
publichasTag
Check if a tag exists on the entity
Parameters
tag: string
name to check for
Returns boolean
publicisKilled
Indicates wether the actor has been killed.
Returns boolean
publickill
If the current actor is a member of the scene, this will remove it from the scene graph. It will no longer be drawn or updated.
Returns void
publicoff
Unsubscribe an event handler(s) from an event. If a specific handler is specified for an event, only that handler will be unsubscribed. Otherwise all handlers will be unsubscribed for that event.
Type parameters
- TEventName: EventKey<ActorEvents>
Parameters
eventName: TEventName
The name of the event to unsubscribe
handler: Handler<ActorEvents[TEventName]>
Optionally the specific handler to unsubscribe
Returns void
publicon
Subscribe an event handler to a particular event name, multiple handlers per event name are allowed.
Type parameters
- TEventName: EventKey<ActorEvents>
Parameters
eventName: TEventName
The name of the event to subscribe to
handler: Handler<ActorEvents[TEventName]>
The handler callback to fire on this event
Returns Subscription
publiconCollisionEnd
Fires once when 2 entities with a ColliderComponent separate after having been in contact.
Parameters
self: Collider
other: Collider
side: Side
lastContact: CollisionContact
Returns void
publiconCollisionStart
Fires once when 2 entities with a ColliderComponent first start colliding or touching, if the Colliders stay in contact this does not continue firing until they separate and re-collide.
Parameters
self: Collider
other: Collider
side: Side
contact: CollisionContact
Returns void
publiconInitialize
onInitialize
is called before the first update of the actor. This method is meant to be overridden. This is where initialization of child actors should take place.Synonymous with the event handler
.on('initialize', (evt) => {...})
Parameters
engine: Engine<any>
Returns void
publiconPostCollisionResolve
Fires after every resolution for a confirmed contact.
Parameters
self: Collider
other: Collider
side: Side
contact: CollisionContact
Returns void
publiconPostKill
Safe to override onPostKill lifecycle event handler. Synonymous with
.on('postkill', (evt) => {...})
onPostKill
is called directly after an actor is killed and remove from its current [[Scene]].Parameters
scene: Scene<unknown>
Returns void
publiconPostUpdate
Safe to override onPostUpdate lifecycle event handler. Synonymous with
.on('postupdate', (evt) =>{...})
onPostUpdate
is called directly after an actor is updated.Parameters
engine: Engine<any>
delta: number
Returns void
publiconPreCollisionResolve
Fires before every collision resolution for a confirmed contact
Parameters
self: Collider
other: Collider
side: Side
contact: CollisionContact
Returns void
publiconPreKill
Safe to override onPreKill lifecycle event handler. Synonymous with
.on('prekill', (evt) =>{...})
onPreKill
is called directly before an actor is killed and removed from its current [[Scene]].Parameters
scene: Scene<unknown>
Returns void
publiconPreUpdate
Safe to override onPreUpdate lifecycle event handler. Synonymous with
.on('preupdate', (evt) =>{...})
onPreUpdate
is called directly before an actor is updated.Parameters
engine: Engine<any>
delta: number
Returns void
publiconce
Once listens to an event once then auto unsubscribes from that event
Type parameters
- TEventName: EventKey<ActorEvents>
Parameters
eventName: TEventName
The name of the event to subscribe to once
handler: Handler<ActorEvents[TEventName]>
The handler of the event that will be auto unsubscribed
Returns Subscription
publicremoveAllChildren
Removes all children from this entity
Returns Entity<any>
publicremoveChild
publicremoveComponent
Removes a component from the entity, by default removals are deferred to the end of entity update to avoid consistency issues
Components can be force removed with the
force
flag, the removal is not deferred and happens immediatelyType parameters
- TComponent: Component
Parameters
typeOrInstance: TComponent | ComponentCtor<TComponent>
force: boolean = false
Returns Entity<Exclude<any, TComponent>>
publicremoveParticle
Parameters
particle: Particle
Returns void
publicremoveTag
Removes a tag on the entity
Removals are deferred until the end of update
Parameters
tag: string
Returns Entity<any>
publicunkill
If the current actor is killed, it will now not be killed.
Returns void
publicunparent
Unparents this entity, if there is a parent. Otherwise it does nothing.
Returns void
publicupdate
Parameters
engine: Engine<any>
delta: number
Returns void
publicwithin
Returns true if the two actor.collider's surfaces are less than or equal to the distance specified from each other
Parameters
actor: Actor
Actor to test
distance: number
Distance in pixels to test
Returns boolean
Using a particle emitter is a great way to create interesting effects in your game, like smoke, fire, water, explosions, etc.
ParticleEmitter
extend [[Actor]] allowing you to use all of the features that come with.