MCPcopy
hub / github.com/KilledByAPixel/LittleJS / keyDirection

Function keyDirection

src/engineInput.js:142–150  ·  view source on GitHub ↗

Returns input vector from arrow keys or WASD if enabled * @param {string} [up] * @param {string} [down] * @param {string} [left] * @param {string} [right] * @return {Vector2} * @memberof Input

(up='ArrowUp', down='ArrowDown', left='ArrowLeft', right='ArrowRight')

Source from the content-addressed store, hash-verified

140 * @return {Vector2}
141 * @memberof Input */
142function keyDirection(up='ArrowUp', down='ArrowDown', left='ArrowLeft', right='ArrowRight')
143{
144 ASSERT(isStringLike(up), 'up key must be a string');
145 ASSERT(isStringLike(down), 'down key must be a string');
146 ASSERT(isStringLike(left), 'left key must be a string');
147 ASSERT(isStringLike(right), 'right key must be a string');
148 const k = (key)=> keyIsDown(key) ? 1 : 0;
149 return vec2(k(right) - k(left), k(up) - k(down));
150}
151
152/** Returns true if mouse button is down
153 * @function

Callers 8

gameUpdateFunction · 0.85
updateMethod · 0.85
updateMethod · 0.85
updateMethod · 0.85
updateMethod · 0.85
updateMethod · 0.85
updateMethod · 0.85
gameUpdateFunction · 0.85

Calls 4

isStringLikeFunction · 0.85
vec2Function · 0.85
ASSERTFunction · 0.70
kFunction · 0.70

Tested by

no test coverage detected