examples/platformer/js/entities/controls.js
function (x, y) {
        if (x - this.pos.x < this.width / 2) {
            if (this.cursors.left === false) {
                me.input.triggerKeyEvent(me.input.KEY.LEFT, true);
                this.cursors.left = true;
                this.joypad_offset.x = -((this.width / 2 - (x - this.pos.x)) % this.pad.width / 4);
            }
            // release the right key if it was pressed
            if (this.cursors.right === true) {
                me.input.triggerKeyEvent(me.input.KEY.RIGHT, false);
                this.cursors.right = false;
            }
        }
        if (x - this.pos.x > this.width / 2) {
            if (this.cursors.right === false) {
                me.input.triggerKeyEvent(me.input.KEY.RIGHT, true);
                this.cursors.right = true;
                this.joypad_offset.x = +(((x - this.pos.x) - this.width / 2) % this.pad.width / 4);
            }
            // release the left key is it was pressed
            if (this.cursors.left === true) {
                me.input.triggerKeyEvent(me.input.KEY.LEFT, false);
                this.cursors.left = false;
            }
        }
    }
function (x, y) {
        if (x - this.pos.x < this.width / 2) {
            if (this.cursors.left === false) {
                me.input.triggerKeyEvent(me.input.KEY.LEFT, true);
                this.cursors.left = true;
                this.joypad_offset.x = -((this.width / 2 - (x - this.pos.x)) % this.pad.width / 4);
            }
            // release the right key if it was pressed
            if (this.cursors.right === true) {
                me.input.triggerKeyEvent(me.input.KEY.RIGHT, false);
                this.cursors.right = false;
            }
        }
        if (x - this.pos.x > this.width / 2) {
            if (this.cursors.right === false) {
                me.input.triggerKeyEvent(me.input.KEY.RIGHT, true);
                this.cursors.right = true;
                this.joypad_offset.x = +(((x - this.pos.x) - this.width / 2) % this.pad.width / 4);
            }
            // release the left key is it was pressed
            if (this.cursors.left === true) {
                me.input.triggerKeyEvent(me.input.KEY.LEFT, false);
                this.cursors.left = false;
            }
        }
    }
function ( x , y ) { if ( x - this . pos . x < this . width / 2 ) { if ( this . cursors . left === false ) { me . input . triggerKeyEvent ( me . input . KEY . LEFT , true ) ; this . cursors . left = true ; this . joypad_offset . x = - ( ( this . width / 2 - ( x - this . pos . x ) ) % this . pad . width / 4 ) ; } // release the right key if it was pressed if ( this . cursors . right === true ) { me . input . triggerKeyEvent ( me . input . KEY . RIGHT , false ) ; this . cursors . right = false ; } } if ( x - this . pos . x > this . width / 2 ) { if ( this . cursors . right === false ) { me . input . triggerKeyEvent ( me . input . KEY . RIGHT , true ) ; this . cursors . right = true ; this . joypad_offset . x = + ( ( ( x - this . pos . x ) - this . width / 2 ) % this . pad . width / 4 ) ; } // release the left key is it was pressed if ( this . cursors . left === true ) { me . input . triggerKeyEvent ( me . input . KEY . LEFT , false ) ; this . cursors . left = false ; } } }
update the cursors value and trigger key event
update the cursors value and trigger key event