ig.

EntityTrigger

new EntityTrigger()

Trigger calling the activate function of each of its targets when a checked against entity enters it. Tip: many entities descend from trigger, so make sure to check before adding a trigger to trigger a trigger!

Author:
  • Collin Hover - collinhover.com
  • Dominic Szablewski
Source:
Example
// the trigger process is linear
// to start, the trigger needs to check against a type of entity
// by default, triggers only check against the player
ig.utils.addType(ig.EntityExtended, trigger, 'checkAgainst', "PLAYER");
// triggers can be expanded to check against other things, such as characters
ig.utils.addType(ig.EntityExtended, trigger, 'checkAgainst', "CHARACTER");
// or to ONLY check against a certain type
trigger.checkAgainst = 0;
ig.utils.addType(ig.EntityExtended, trigger, 'checkAgainst', "CERTAIN_TYPE");
// once the trigger checks against one of these types of entities
// the trigger automatically calls its trigger method (after an optional delay)
trigger.trigger( entityOfType );
// provided you've added the names of targets
trigger.target.1 = "unique_target_001";
trigger.target.2 = "unique_target_002";
// during the trigger method, targets are found by name and activated
target = ig.game.namedEntities[this.target[ name ]];
target.activate( entityOfType );
// and after all targets are taken care of, trigger activates itself
// this can be useful for entities that extend the trigger
// ex: instagib entity that kills player when they fall out of bounds
trigger.activate( entityOfType );
// also, the trigger deactivate method will reverse the trigger state
// and is useful for triggers that only activate once
trigger.deactivate( entity );
// and it is important to note that triggers are suicidal
// i.e. after triggering they remove themselves from the game
// but this can be changed easily
trigger.suicidal = false;

autoComplete :Boolean

Whether trigger should automatically call the complete method when finished triggering. Tip: set this to false to handle completing manually!

Default Value:
  • true
Source:

autoToggle :Boolean

Whether trigger should auto toggle back to default state after done checking against an entity.

Default Value:
  • false
Source:

delay :Number

Duration in seconds to delay activation.

Default Value:
  • 0
Source:

delayTimer :ig.Timer

Timer to handle delay duration.
- created on init

Source:

frozen

Triggers do not need to update.

Default Value:
  • true
Source:

once :Boolean

Whether trigger can only activate once before needed to be deactivated.

Default Value:
  • true
Source:

onCompleted :ig.Signal

Signal dispatched when trigger completes triggering.
- created on init

Source:

sortTargetsBy :function

Method to sort targets by when triggered.

Default Value:
  • null
Source:

suicidal :Boolean

Whether trigger kills itself after triggering once.

Default Value:
  • true
Source:

target :Object

Map of names of target entities to activate when activated.

Source:
Example
// a trigger can trigger any entity by name
entityA.name = 'foo';
triggerA.target.1 = 'foo';
// a trigger can trigger another trigger by name to create a chain
triggerA.name = 'bar';
triggerB.target.1 = 'bar';

<readonly> targetSequence :Array

Sorted list of targets, populated when triggered.

Source:

teardownWhenComplete :Boolean

Whether trigger should call the ig.EntityTrigger#teardown method when complete, or only on deactivate and cleanup.

Default Value:
  • true
Source:

triggerable :Boolean

Whether trigger can be triggered through collision.

Default Value:
  • true
Source:

triggerAfterDelay :Boolean

Whether trigger should activate after delay regardless of whether triggering entity is still there.

Default Value:
  • false
Source:

<readonly> triggering :Boolean

Whether trigger is in the process of triggering.

Default Value:
  • false
Source:

useCheckingAsTarget :Boolean

Whether entity that checks and causes trigger to activate should be used as a target.

Default Value:
  • false
Source:

wait :Number

Duration in seconds before this trigger can be activated again.

Default Value:
  • 0
Source:

waitTimer :ig.Timer

Timer to handle wait duration.
- created on init

Source:

activate()

Activates and tries to trigger to ensure that triggers chain.

Source:

check()

Checks trigger against entity and tries to trigger.

Source:

cleanup()

Source:

complete()

Called when finished triggering.

Source:

deactivate()

Deactivates and tears down trigger.

Source:

getCanTrigger(entity) → {Boolean}

Gets whether trigger can be triggered.

Parameters:
Name Type Description
entity ig.EntityExtended entity trying to trigger this trigger.
Source:
Returns:
{ Boolean } whether trigger can be triggered.

handleTargets(entity, needsActivation)

Handles activating all self and targets in the target sequence. Tip: override this method to change how the trigger and each target is activated.

Parameters:
Name Type Argument Default Description
entity ig.EntityExtended entity calling trigger.
needsActivation Boolean <optional>
true whether to activating self in addition to targets
Source:

initProperties()

Initializes trigger properties.

Source:
See:
  • ig.EntityExtended.

initTypes()

Initializes trigger types.
- adds ig.EntityExtended.TYPE.TRIGGER to {@link ig.EntityExtended#type}
- adds ig.EntityExtended.TYPE.PLAYER to {@link ig.EntityExtended#checkAgainst}

Source:

kill()

Source:

pause()

Source:

resetExtras()

Source:

setup()

Sets up trigger and makes temporary modifications, which are removed by ig.EntityTrigger#teardown. Tip: setup is called only on activate, while teardown is called on the 1) complete, 2) deactivate, and 3) cleanup methods. Complete is normally called immediately after activating/triggering, so if you don't want to teardown immediately use the ig.EntityTrigger#teardownWhenComplete property.

Source:

teardown()

Tears down trigger and cleans up any temporary modifications trigger made by ig.EntityTrigger#setup. Tip: setup is called only on activate, while teardown is called on the 1) complete, 2) deactivate, and 3) cleanup methods. Complete is normally called immediately after activating/triggering, so if you don't want to teardown immediately use the ig.EntityTrigger#teardownWhenComplete property.

Source:

trigger(entity, needsActivation, entityIsChecking)

Called when triggering to activate self and all targets.

Parameters:
Name Type Argument Default Description
entity ig.EntityExtended <optional>
entity calling trigger.
needsActivation Boolean <optional>
true whether to activating self in addition to targets.
entityIsChecking Boolean <optional>
false whether entity is checking.
Source:

unpause()

Source:

update()

Updates trigger and checks whether should trigger after delay.

Source: