Controllable Component

Used to bind methods to generalized input events.

Currently supports the events "DirectionalInput", "TriggerInputDown", and "TriggerInputUp".

Methods

Back to top

.disableControl()

public this .disableControl()

Disable the component from responding to input events.

Example

this.disableControl();
Back to top

.enableControl()

public this .enableControl()

Enable the component to listen to input events.

Example

this.enableControl();
Back to top

.linkInput()

public this linkInput(string event, string name, function fn)
event

the name of the input event

name

the name of the input

fn

the function that will be called with the event object

Binds the function to the particular named event trigger.

Currently supports three types of input events. Each event will have a name property.

  • DirectionalInput: The event will have x and y properties representing the directional input vector, often normalized to a unit vector. Triggered when the input changes.
  • TriggerInputDown: Occurs when the input is triggered.
  • TriggerInputDown: Occurs when the trigger is released. The event will have a downFor property, indicating how long it had been active.

Example

// Create a trigger bound to the `b` key
Crafty.s("Controls").defineTriggerGroup("BlushTrigger", {keys:['b']});
// Create a blue square that turns pink when the trigger is pressed
Crafty.e("2D, Canvas, Color, Controllable")
  .attr({x:10, y:10, h:10, w:10}).color("blue")
  .linkInput("TriggerInputDown", "BlushTrigger", function(){this.color('pink');});

See Also

Back to top

.unlinkInput()

public this linkInput(string event, string name)
event

the name of the input event

name

the name of the input

Removes a binding setup by linkInput

See Also