Trigger options
Direct access to the actor's ActionQueue. Useful if you are building custom actions.
Action context of the actor. Useful for scripting actor behavior.
Whether this entity is active, if set to false it will be reclaimed
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 be
Actor.anchor.setTo(0, 0)
and top-right would be Actor.anchor.setTo(0, 1)
.
The children of this actor
Access to the current drawing for the actor, this can be an Animation, Sprite, or Polygon. Set drawings with setDrawing.
Whether or not to enable the CapturePointer trait that propagates pointer events to this actor
Direct access to the game object event dispatcher.
The unique identifier for the actor
Indicates whether the actor is physically in the viewport
Convenience reference to the global logger
The opacity of an actor. Passing in a color in the constructor will use the color's opacity.
The parent of this actor
Number of times to repeat before killing the trigger,
The scene that the actor is in
Modify the current actor update pipeline.
The visibility of an actor
Indicates the next id to be set
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.
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.
Get the center point of an actor
Sets the color of the actor. A rectangle of this color will be drawn if no Drawable is specified as the actors drawing.
The default is null
which prevents a rectangle from being drawn.
Sets the color of the actor. A rectangle of this color will be drawn if no Drawable is specified as the actors drawing.
The default is null
which prevents a rectangle from being drawn.
Gets whether the actor is Initialized
Gets the acceleration of the actor from the last frame. This does not include the global acc Physics.acc.
Sets the acceleration of the actor from the last frame. This does not include the global acc Physics.acc.
Gets the rotation of the actor in radians. 1 radian = 180/PI Degrees.
Sets the rotation of the actor in radians. 1 radian = 180/PI Degrees.
Gets the rotational velocity of the actor in radians/second
Sets the rotational velocity of the actor in radians/sec
Gets the x scalar velocity of the actor in scale/second
Sets the x scalar velocity of the actor in scale/second
Gets the y scalar velocity of the actor in scale/second
Sets the y scale velocity of the actor in scale/second
The types of the components on the Entity
It is not recommended that internal excalibur methods be overridden, do so at your own risk.
Internal _postdraw handler for onPostDraw lifecycle event
It is not recommended that internal excalibur methods be overridden, do so at your own risk.
Internal _prekill handler for onPostKill lifecycle event
It is not recommended that internal excalibur methods be overridden, do so at your own risk.
Internal _preupdate handler for onPostUpdate lifecycle event
It is not recommended that internal excalibur methods be overridden, do so at your own risk.
Internal _predraw handler for onPreDraw lifecycle event
It is not recommended that internal excalibur methods be overridden, do so at your own risk.
Internal _preupdate handler for onPreUpdate lifecycle event
Action to fire when triggered by collision
Adds a child actor to this actor. All movement of the child actor will be relative to the parent actor. Meaning if the parent moves the child will move with it.
The child actor to add
Adds a whole texture as the "default" drawing. Set a drawing using setDrawing.
Adds a whole sprite as the "default" drawing. Set a drawing using setDrawing.
Adds a drawing to the list of available drawings for an actor. Set a drawing using setDrawing.
The key to associate with a drawing for this actor
Creates a deep copy of the entity and a copy of all its components
Tests whether the x/y specified are contained in the actor
X coordinate to test (in world coordinates)
Y coordinate to test (in world coordinates)
checks whether the x/y are contained in any child actors (if they exist).
Called by the Engine, draws the actor to the screen
The rendering context
The time since the last draw in milliseconds
Emits a new event
Name of the event to emit
Data associated with this event
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 actor.
Returns the full array of ancestors
Gets the global scale of the Actor
Gets an actor's world position taking into account parent relationships, scaling, rotation, and translation
Position in world coordinates
Gets this actor's rotation taking into account any parent relationships
Rotation angle in radians
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
Indicates wether the actor has been killed.
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.
The collisionstart event is fired when a physics body, usually attached to an actor, first starts colliding with another body, and will not fire again while in contact until the the pair separates and collides again. Use cases for the collisionstart event may be detecting when an actor has touch a surface (like landing) or if a item has been touched and needs to be picked up.
The collisionend event is fired when two physics bodies are no longer in contact. This event will not fire again until another collision and separation.
Use cases for the collisionend event might be to detect when an actor has left a surface (like jumping) or has left an area.
The precollision event is fired every frame where a collision pair is found and two bodies are intersecting.
This event is useful for building in custom collision resolution logic in Passive-Passive or Active-Passive scenarios. For example in a breakout game you may want to tweak the angle of ricochet of the ball depending on which side of the paddle you hit.
The postcollision event is fired for every frame where collision resolution was performed. Collision resolution is when two bodies influence each other and cause a response like bouncing off one another. It is only possible to have postcollision event in Active-Active and Active-Fixed type collision pairs.
Post collision would be useful if you need to know that collision resolution is happening or need to tweak the default resolution.
The collisionstart event is fired when a physics body, usually attached to an actor, first starts colliding with another body, and will not fire again while in contact until the the pair separates and collides again. Use cases for the collisionstart event may be detecting when an actor has touched a surface (like landing) or if a item has been touched and needs to be picked up.
The collisionend event is fired when two physics bodies are no longer in contact. This event will not fire again until another collision and separation.
Use cases for the collisionend event might be to detect when an actor has left a surface (like jumping) or has left an area.
The precollision event is fired every frame where a collision pair is found and two bodies are intersecting.
This event is useful for building in custom collision resolution logic in Passive-Passive or Active-Passive scenarios. For example in a breakout game you may want to tweak the angle of ricochet of the ball depending on which side of the paddle you hit.
The postcollision event is fired for every frame where collision resolution was performed. Collision resolution is when two bodies influence each other and cause a response like bouncing off one another. It is only possible to have postcollision event in Active-Active and Active-Fixed type collision pairs.
Post collision would be useful if you need to know that collision resolution is happening or need to tweak the default resolution.
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) => {...})
Safe to override onPostDraw lifecycle event handler. Synonymous with .on('postdraw', (evt) =>{...})
onPostDraw
is called directly after an actor is drawn, and before local transforms are removed.
Safe to override onPostUpdate lifecycle event handler. Synonymous with .on('postupdate', (evt) =>{...})
onPostUpdate
is called directly after an actor is updated.
Safe to override onPreDraw lifecycle event handler. Synonymous with .on('predraw', (evt) =>{...})
onPreDraw
is called directly before an actor is drawn, but after local transforms are made.
Safe to override onPreUpdate lifecycle event handler. Synonymous with .on('preupdate', (evt) =>{...})
onPreUpdate
is called directly before an actor is updated.
The collisionstart event is fired when a physics body, usually attached to an actor, first starts colliding with another body, and will not fire again while in contact until the the pair separates and collides again. Use cases for the collisionstart event may be detecting when an actor has touch a surface (like landing) or if a item has been touched and needs to be picked up.
The collisionend event is fired when two physics bodies are no longer in contact. This event will not fire again until another collision and separation.
Use cases for the collisionend event might be to detect when an actor has left a surface (like jumping) or has left an area.
The precollision event is fired every frame where a collision pair is found and two bodies are intersecting.
This event is useful for building in custom collision resolution logic in Passive-Passive or Active-Passive scenarios. For example in a breakout game you may want to tweak the angle of ricochet of the ball depending on which side of the paddle you hit.
The postcollision event is fired for every frame where collision resolution was performed. Collision resolution is when two bodies influence each other and cause a response like bouncing off one another. It is only possible to have postcollision event in Active-Active and Active-Fixed type collision pairs.
Post collision would be useful if you need to know that collision resolution is happening or need to tweak the default resolution.
Removes a child actor from this actor.
The child actor to remove
Removes a component from the entity, by default removals are deferred to the end of entity processing to avoid consistency issues
Components can be force removed with the force
flag, the removal is not deferred and happens immediately
Sets the current drawing of the actor to the drawing corresponding to the key.
The key of the drawing
Sets the current drawing of the actor to the drawing corresponding to
an enum
key (e.g. Animations.Left
)
The enum
key of the drawing
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
new z-index to assign
If the current actor is killed, it will now not be killed.
Called by the Engine, updates the state of the actor
The reference to the current game engine
The time elapsed since the last update in milliseconds
Returns true if the two actor.body.collider.shape's surfaces are less than or equal to the distance specified from each other
Actor to test
Distance in pixels to test
Configuration for CapturePointer trait
Indicates the next id to be set
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
.Creating a trigger
// Start the engine var game = new ex.Engine({ width: 800, height: 600, displayMode: ex.DisplayMode.FullScreen }); // Uncomment next line to make the trigger box visible // game.isDebug = true; // create a handler function onTrigger() { // `this` will be the Trigger instance ex.Logger.getInstance().info('Trigger was triggered!', this); } // set a trigger at (100, 100) that is 40x40px that can only be fired once var trigger = new ex.Trigger({ width: 40, height: 40, pos: new ex.Vector(100, 100), repeat: 1, target: actor, action: onTrigger }); // create an actor above the trigger var actor = new ex.Actor(100, 0, 40, 40, ex.Color.Red); // Enable collision on actor (else trigger won't fire) actor.body.collider.type = ex.CollisionType.Active; // tell the actor to move across the trigger with a velocity of 100 actor.actions.moveTo(100, 200, 100); // Add trigger and actor to our scene and start the scene game.add(trigger); game.add(actor); game.start();