Controllable 组件
用于将方法绑定到一般的输入事件。
目前支持的事件有 "DirectionalInput", "TriggerInputDown", 和 "TriggerInputUp".
方法
Back to top
.linkInput()
public this linkInput(string event, string name, function fn)- event
输入事件的名称。
- name
输入的名称
- fn
事件回调函数
将函数绑定到特定名称的事件触发器
当前支持三种类型的输入事件。每个事件都有一个name属性。
DirectionalInput: 该事件将具有表示定向输入向量的x和y属性,通常将其规范为单位向量。当输入更改时触发。TriggerInputDown: 当输入被触发时发生。TriggerInputUp: 触发被释放时发生。该事件将有一个downFor属性,指示被激活了多久。
例子
// Create a trigger bound to the `b` key
Crafty.s("Controls").defineTriggerInput("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');});Back to top
.unlinkInput()
public this linkInput(string event, string name)- event
输入事件的名称。
- name
输入的名称
移除一个使用 linkInput 建立的绑定
google groups
starwed@gmail.com
github