I’m making a menu system for my game’s title screen and I want to be able to select a menu item using the spacebar. I can currently do it using the enter key, but I would prefer to be able to do it using the spacebar as well. This is the code I’m using for the menu navigation:
this.input.keyboard.on('keydown', event => {
switch (event.key) {
case 'ArrowUp':
activeText -= 1;
this.events.emit('CHANGE_BUTTON');
break;
case 'ArrowDown':
activeText += 1;
this.events.emit('CHANGE_BUTTON');
break;
case 'Enter':
this.events.emit('SELECT');
break;
//this particular instance doesn't work:
case 'SpaceBar':
this.events.emit('SELECT');
break;
}
});
I’ve been looking around the documentation, but I can’t seem to find any examples where spacebar isn’t added separately (and even when I tried to add it in that way, it wasn’t recognised)
Any help would be appreciated