2

I am using shake.js and I am modifying a game. The avatar jumps fine with button press but with the shake it jumps once and refuses to jump more. I am sure that the shake event is still firing because I can get the alert to pop up. Anybody have any idea what is happening inside of the shake action that is different than that for the keypress? Thank you!

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);
                    },
                }, ],
            });
        };
Stal G
  • 128
  • 1
  • 7

0 Answers0