1 decade ago by camprad
I'm not able to get my game to recognize that the keypress has gone up. My guy shoots continuously and constantly moves right or left, even after I stop pressing the key. Here's my code:
// Bind keys ig.input.bind( ig.KEY.LEFT_ARROW, 'left' ); ig.input.bind( ig.KEY.RIGHT_ARROW, 'right' ); ig.input.bind( ig.KEY.X, 'jump' ); ig.input.bind( ig.KEY.C, 'shoot' ); // move left or right var accel = this.standing ? this.accelGround : this.accelAir; if( ig.input.state('left') ) { this.accel.x = -accel; this.flip = true; alert("you pressed left"); }else if( ig.input.state('right') ) { this.accel.x = accel; this.flip = false; alert("you pressed right"); }else{ this.accel.x = 0; } // jump if( this.standing && ig.input.pressed('jump') ) { this.vel.y = -this.jump; this.jumpSFX.play(); } // shoot if( ig.input.state('shoot') ) { ig.game.spawnEntity( this.activeWeapon, this.pos.x, this.pos.y, {flip:this.flip} ); this.shootSFX.play(); alert("you pressed c"); }