Timmey

Members
  • Content count

    2
  • Joined

  • Last visited

  1. You are also enabling physics on your scenery layer. Might want change that one as well. //assign physics to the layer 'floor' game.physics.arcade.enable(layers[3]);
  2. Heya, I ran against the issue of assigning multiple KeyCodes per action as well. Here is a little bit of code I wrote to deal with it. I hope it might be useful to some people. (Warning: this example requires lodash or underscore, also make sure all the variables are available in the different functions) // Define your actionsvar ACTIONS = { LEFT: 1, UP: 2, RIGHT: 3, DOWN: 4, ATTACK: 5, BASIC_ATTACK: 6,};// Define your keymap, as many keys per action as we wantvar defaultKeymap = { [ACTION.LEFT]: [Phaser.KeyCode.A, Phaser.KeyCode.LEFT], [ACTION.UP]: [Phaser.KeyCode.W, Phaser.KeyCode.UP], [ACTION.RIGHT]: [Phaser.KeyCode.D, Phaser.KeyCode.RIGHT], [ACTION.DOWN]: [Phaser.KeyCode.S, Phaser.KeyCode.DOWN], [ACTION.BASIC_ATTACK]: Phaser.KeyCode.CONTROL};// Create Keymap classvar Keymap = function( keyboard, defaultKeymap ) { this.map = {}; var self = this; _.forEach(defaultKeymap, function(KeyCode, action) { self.map[action] = []; if(_.isArray(KeyCode)) { _.forEach(KeyCode, (code) => { self.map[action].push(keyboard.addKey(code)); }); } else { self.map[action].push(keyboard.addKey(KeyCode)); } });};// isDown function for your actionKeymap.prototype.isDown = function(action) { for(let i = 0, length = this.map[action].length; i < length; i++ ){ if(this.map[action][i].isDown) { return true; } } return false;};// Create the Keymapvar myMap = new Keymap(game.input.keyboard, defaultKeymap);// In your update function you can now useif( myMap.isDown(ACTION.LEFT) ) { // do stuff}Yours, Timmey