1 decade ago by jazun33
I've been folloing along Jesse Freeman's book, "HTML5 Games with ImpactJS" and I got to the part where I've added key bindings to the player's movement. I wanted to experiment with adding in gamepad support with this plugin (http://impactjs.com/forums/code/working-gamepad-support-for-chrome-22) but something weird is happening to the normal arrow key bindings. When the gamepad is enabled the arrow keys move the player very slowly and stuttery when you hold them down but the controller works fine. It's really bizarre. I'm using a logitech f310 in x-input. If you have a gamepad you're welcome to try it out.
Edit: I only get this issue AFTER I've pressed a button on the gamepad. So if you're coming into this without a gamepad and start messing with the arrow keys there will be no problem. Once you've pressed a button on the gamepad tho, it's almost as if it doesn't like arrow keys anymore.
Here's a link to the game.
So far, here is my main.js code:
Edit: I only get this issue AFTER I've pressed a button on the gamepad. So if you're coming into this without a gamepad and start messing with the arrow keys there will be no problem. Once you've pressed a button on the gamepad tho, it's almost as if it doesn't like arrow keys anymore.
Here's a link to the game.
So far, here is my main.js code:
ig.module( 'game.main' ) .requires( 'impact.game', 'impact.animation', 'game.levels.dorm1', 'game.entities.player', 'plugins.gamepad.gamepad' ) .defines(function(){ MyGame = ig.Game.extend({ gravity: 300, // Load a font font: new ig.Font( 'media/04b03.font.png' ), init: function() { // Initialize your game here; bind keys etc. this.loadLevel( LevelDorm1 ); 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' ); }, update: function() { // Add your own, additional update code here var player = this.getEntitiesByType(EntityPlayer)[0]; if(player){ this.screen.x = player.pos.x - ig.system.width/2; this.screen.y = player.pos.y - ig.system.height/2; } //Gamepad support var gamepad = new Gamepad.getState(0); var mappings = [[ gamepad.dpadLeft, ig.KEY.LEFT_ARROW ], [ gamepad.dpadRight, ig.KEY.RIGHT_ARROW ], [ gamepad.faceButton0, ig.KEY.X ], [ gamepad.faceButton1, ig.KEY.C ]]; new Gamepad.magic(gamepad, mappings); // Update all entities and backgroundMaps this.parent(); }, draw: function() { // Draw all entities and backgroundMaps this.parent(); // Add your own drawing code here } }); // Start the Game with 60fps, a resolution of 320x240, scaled // up by a factor of 2 ig.main( '#canvas', MyGame, 60, 320, 240, 2 ); });