From 275fca78064d1c932a801fbc65648b89ed0f86a8 Mon Sep 17 00:00:00 2001 From: Colin van Eenige Date: Tue, 24 Jul 2018 22:20:58 +0200 Subject: [PATCH] Update demo for two controllers. --- demo/src/index.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/demo/src/index.js b/demo/src/index.js index dcf66d9..e39f26b 100644 --- a/demo/src/index.js +++ b/demo/src/index.js @@ -6,22 +6,35 @@ function logButton(control, state) { ul.innerHTML = `
  • ${control} was ${state ? 'pressed' : 'released'}
  • ${ul.innerHTML}`; } -function LogAxes(position) { - ul.innerHTML = `
  • Axes position ${position}
  • ${ul.innerHTML}`; +function LogAxes(controller, position) { + ul.innerHTML = `
  • ${controller} ~ Axes position ${position}
  • ${ul.innerHTML}`; } -const controller = new Controller({ - b: pressed => logButton('B', pressed), - a: pressed => logButton('A', pressed), - y: pressed => logButton('Y', pressed), - x: pressed => logButton('X', pressed), - l: pressed => logButton('L', pressed), - r: pressed => logButton('R', pressed), - axes: position => LogAxes(position), +const controllerLeft = new Controller({ + side: 'L', + b: pressed => logButton('1 ~ B', pressed), + a: pressed => logButton('1 ~ A', pressed), + y: pressed => logButton('1 ~ Y', pressed), + x: pressed => logButton('1 ~ X', pressed), + l: pressed => logButton('1 ~ L', pressed), + r: pressed => logButton('1 ~ R', pressed), + axes: position => LogAxes('1', position), +}); + +const controllerRight = new Controller({ + side: 'R', + b: pressed => logButton('2 ~ B', pressed), + a: pressed => logButton('2 ~ A', pressed), + y: pressed => logButton('2 ~ Y', pressed), + x: pressed => logButton('2 ~ X', pressed), + l: pressed => logButton('2 ~ L', pressed), + r: pressed => logButton('2 ~ R', pressed), + axes: position => LogAxes('2', position), }); function render() { - controller.update(); + controllerLeft.update(); + controllerRight.update(); requestAnimationFrame(render); }