Trigger
Hierarchy
- Actor
- Trigger
Index
Constructors
Properties
Accessors
Methods
- addChild
- addComponent
- addTag
- addTemplate
- clearComponents
- clone
- contains
- emit
- get
- getAncestors
- getComponents
- getDescendants
- getGlobalPos
- getGlobalRotation
- getGlobalScale
- has
- hasAll
- hasAllTags
- hasChild
- hasTag
- isKilled
- kill
- off
- on
- onAdd
- once
- onCollisionEnd
- onCollisionStart
- onInitialize
- onPostCollisionResolve
- onPostKill
- onPostUpdate
- onPreCollisionResolve
- onPreKill
- onPreUpdate
- onRemove
- removeAllChildren
- removeChild
- removeComponent
- removeTag
- unkill
- unparent
- within
Constructors
constructor
Parameters
options: TriggerOptions & ActorArgs
Trigger options
Returns Trigger
Properties
publicinherited_componentsToRemove
publicaction
publicinheritedactions
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
Action context of the actor.
publicinheritedbody
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.
publicinheritedchildrenAdded$
publicinheritedchildrenRemoved$
publicinheritedcollider
Access to the Actor's built in ColliderComponent
publicinheritedcomponentAdded$
publicinheritedcomponentRemoved$
publicreadonlyinheritedcomponents
Current components on the entity
Do not modify
Use addComponent/removeComponent otherwise the ECS will not be notified of changes.
publicinheritedcomponentValues
publicevents
Listen to or emit events for an entity
publicfilter
Filter to add additional granularity to action dispatch, if a filter is specified the action will only fire when filter return true for the collided entity.
Type declaration
Parameters
entity: Entity
Returns boolean
publicinheritedgraphics
Access to the Actor's built in GraphicsComponent
publicinheritedid
The unique identifier for the entity
publicinheritedisActive
Whether this entity is active, if set to false it will be reclaimed
publicinheritedlogger
Convenience reference to the global logger
publicinheritedmotion
Access the Actor's built in MotionComponent
publicinheritedname
publicinheritedpaused
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.
publicinheritedpointer
Access to the Actor's built in PointerComponent config
publicrepeat
Number of times to repeat before killing the trigger,
publicinheritedscene
The current scene that the entity is in, if any
publicinheritedtagAdded$
publicinheritedtagRemoved$
publicoptionaltarget
publicinheritedtransform
Access the Actor's built in TransformComponent
publicstaticinheriteddefaults
Accessors
publicinheritedacc
publicinheritedactive
Whether this entity is active, if set to false it will be reclaimed
Returns boolean
Whether this entity is active, if set to false it will be reclaimed
Parameters
val: boolean
Returns void
publicinheritedanchor
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.setToto 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
publicinheritedangularVelocity
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
publicinheritedcanPause
Returns boolean
Parameters
canPause: boolean
Returns void
publicinheritedcenter
Get the center point of an actor (global position)
Returns Vector
publicinheritedchildren
Get the direct children of this entity
Returns readonly Entity<any>[]
publicinheritedcolor
publicinheriteddraggable
Returns boolean
Parameters
isDraggable: boolean
Returns void
publicinheritedglobalPos
The actor's world position taking into account parent relationships, scaling, rotation, and translation
Returns Vector
publicinheritedglobalRotation
The actor's rotation (in radians) taking into account any parent relationships
Returns number
publicinheritedglobalScale
The global scale of the Actor
Returns Vector
publicinheritedglobalZ
The global z-index of the actor
Returns number
publicinheritedheight
Returns number
publicinheritedisAdded
Returns boolean
publicinheritedisInitialized
Gets whether the actor is Initialized
Returns boolean
publicinheritedisOffScreen
Indicates whether the actor is physically in the viewport
Returns boolean
publicinheritedisPaused
Returns boolean
publicinheritedlocalCenter
Get the local center point of an actor
Returns Vector
publicinheritedoffset
publicinheritedoldAcc
publicinheritedoldGlobalPos
Gets the global position vector of the actor from the last frame
Returns Vector
publicinheritedoldPos
publicinheritedoldVel
publicinheritedparent
Returns Entity<any> | null
publicinheritedpos
publicinheritedrotation
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
publicinheritedscale
publicinheritedtags
Specifically get the tags on the entity from TagsComponent
Returns Set<string>
publicinheritedtypes
The types of the components on the Entity
Returns ComponentCtor[]
publicinheritedvel
publicinheritedwidth
Returns number
publicinheritedz
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
publicinheritedaddChild
publicinheritedaddComponent
publicinheritedaddTag
Adds a tag to an entity
Parameters
tag: string
Returns Entity<any>
publicinheritedaddTemplate
publicinheritedclearComponents
Returns void
publicinheritedclone
Creates a deep copy of the entity and a copy of all its components
Returns Actor
publicinheritedcontains
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
publicinheritedemit
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
inheritedget
Type parameters
- TComponent: Component
Parameters
type: ComponentCtor<TComponent>
Returns MaybeKnownComponent<TComponent, any>
publicinheritedgetAncestors
Returns a list of parent entities starting with the topmost parent. Includes the current entity.
Returns Entity<any>[]
publicinheritedgetComponents
Returns all component instances on entity
Returns Component[]
publicinheritedgetDescendants
Returns a list of all the entities that descend from this entity. Includes the current entity.
Returns Entity<any>[]
publicinheritedgetGlobalPos
Gets an actor's world position taking into account parent relationships, scaling, rotation, and translation
Returns Vector
Position in world coordinates
publicinheritedgetGlobalRotation
Gets this actor's rotation taking into account any parent relationships
Returns number
Rotation angle in radians
publicinheritedgetGlobalScale
Gets the global scale of the Actor
Returns Vector
publicinheritedhas
Check if a component type exists
Type parameters
- TComponent: Component
Parameters
type: ComponentCtor<TComponent>
Returns boolean
inheritedhasAll
Verifies that an entity has all the required types
Type parameters
- TComponent: Component
Parameters
requiredTypes: ComponentCtor<TComponent>[]
Returns boolean
inheritedhasAllTags
Verifies that an entity has all the required tags
Parameters
requiredTags: string[]
Returns boolean
publicinheritedhasChild
Check if a child entity exists on the parent entity
Parameters
child: Entity
entity to check for
recursive: boolean = false
whether to check recursively
Returns boolean
publicinheritedhasTag
Check if a tag exists on the entity
Parameters
tag: string
name to check for
Returns boolean
publicinheritedisKilled
Indicates whether the actor has been killed.
Returns boolean
publicinheritedkill
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
publicinheritedoff
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
publicinheritedon
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
publicinheritedonAdd
onAddis called when Actor is added to scene. This method is meant to be overridden.Synonymous with the event handler
.on('add', (evt) => {...})Parameters
engine: Engine
Returns void
publicinheritedonce
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
publicinheritedonCollisionEnd
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
publicinheritedonCollisionStart
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
publicinheritedonInitialize
onInitializeis 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
Returns void
publicinheritedonPostCollisionResolve
Fires after every resolution for a confirmed contact.
Parameters
self: Collider
other: Collider
side: Side
contact: CollisionContact
Returns void
publicinheritedonPostKill
publicinheritedonPostUpdate
Safe to override onPostUpdate lifecycle event handler. Synonymous with
.on('postupdate', (evt) =>{...})onPostUpdateis called directly after an actor is updated.Parameters
engine: Engine
The reference to the current game engine
elapsed: number
The time elapsed since the last update in milliseconds
Returns void
publicinheritedonPreCollisionResolve
Fires before every collision resolution for a confirmed contact
Parameters
self: Collider
other: Collider
side: Side
contact: CollisionContact
Returns void
publicinheritedonPreKill
publicinheritedonPreUpdate
Safe to override onPreUpdate lifecycle event handler. Synonymous with
.on('preupdate', (evt) =>{...})onPreUpdateis called directly before an actor is updated.Parameters
engine: Engine
The reference to the current game engine
elapsed: number
The time elapsed since the last update in milliseconds
Returns void
publicinheritedonRemove
onRemoveis called when Actor is removed from a scene. This method is meant to be overridden.Synonymous with the event handler
.on('remove', (evt) => {...})Parameters
engine: Engine
Returns void
publicinheritedremoveAllChildren
Removes all children from this entity
Returns Entity
publicinheritedremoveChild
publicinheritedremoveComponent
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
forceflag, the removal is not deferred and happens immediatelyType parameters
- TComponent: Component
Parameters
typeOrInstance: TComponent | ComponentCtor<TComponent>
force: boolean = false
Returns Entity<Exclude<any, TComponent>>
publicinheritedremoveTag
Removes a tag on the entity
Removals are deferred until the end of update
Parameters
tag: string
Returns Entity<any>
publicinheritedunkill
If the current actor is killed, it will now not be killed.
Returns void
publicinheritedunparent
Unparents this entity, if there is a parent. Otherwise it does nothing.
Returns void
publicinheritedwithin
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
Triggers are a method of firing arbitrary code on collision. These are useful as 'buttons', 'switches', or to trigger effects in a game. By default triggers are invisible, and can only be seen when Trigger.visible is set to
true.