-
Notifications
You must be signed in to change notification settings - Fork 0
6a. Input ‐ handlers
Becuase the old DOM is terrible, and the new DOM is terribly supported, BETA.js provides a different way to handle input.
Buttons are referred to by their names, as listed here.
Starts up the input handling system. The rest of the input functions won't work without calling this first.
BETA.initInput(); // Well done!
Returns whether a button is currently held down.
BETA.initInput();
var isDown = BETA.isButtonDown("Mouse1"); // true or false
Calls a function whenever a given button is pressed. Ignores repeat button-press events fired when a key is held down.
The callback is passed the event object (MouseEvent or KeyboardEvent) as the first argument.
BETA.initInput();
BETA.onButtonDown("Mouse1", function ()
{
var isDown = BETA.isButtonDown("Mouse1"); // true
});
Calls a function whenever a given button is released.
The callback is passed the event object (MouseEvent or KeyboardEvent) as the first argument.
BETA.initInput();
BETA.onButtonUp("Mouse1", function ()
{
var isDown = BETA.isButtonDown("Mouse1"); // false
});
Gets the current mouse position, relative to a canvas renderers top-left corner, in pixels.
Note: May not work correctly if the underlying element has had its CSS attributes (e.g. border) manually modified.
BETA.initInput();
var renderer = BETA.getRenderer("myCanvas");
BETA.onButtonDown("Mouse1", function ()
{
var mouse = BETA.getMousePos(renderer); // Vector, e.g. {x: 250, y: 200}
});