我正在使用shake.js而我正在修改游戏。按下按钮时,头像跳得很好,但是摇动它会跳跃一次并且拒绝跳跃更多。我确信震动事件仍在触发,因为我可以弹出警报。任何人都知道震动动作中发生的事情与按键的动作有什么不同?谢谢!
var handleJump = function(pressed) {
if (g_jump != pressed) {
g_jump = pressed;
g_client.sendCmd('jump', {
jump: pressed,
});
}
};
//listen to shake event
var shakeEvent = new Shake({threshold: 10});
shakeEvent.start();
window.addEventListener('shake', function(){
alert('shake!')
handleJump(true);
}, false);
function stopShake(){
shakeEvent.stop();
}
var keys = {};
keys[Input.cursorKeys.kLeft] = function(e) {
handleLeftRight(e.pressed, 0x1);
}
keys[Input.cursorKeys.kRight] = function(e) {
handleLeftRight(e.pressed, 0x2);
}
keys["Z".charCodeAt(0)] = function(e) {
handleJump(e.pressed);
}
Input.setupKeys(keys);
Touch.setupButtons({
inputElement: $("buttons"),
buttons: [{
element: $("left"),
callback: function(e) {
handleLeftRight(e.pressed, 0x1);
},
}, {
element: $("right"),
callback: function(e) {
handleLeftRight(e.pressed, 0x2);
},
}, {
element: $("up"),
callback: function(e) {
handleJump(e.pressed);
},
}, ],
});
};