Hydra handles most listening through a simple hydra.listen
API.
For continuous checks, add a “ticker” to run every single frame:
// Provides a beta deltaTime to ensure FPS changes
var ticker = lib.listen.addTicker((deltaTime) => {
// Run checks here
})
You can then remove tickers if needed:
lib.listen.removeTicker(ticker)
lib.listen.mouse.x
lib.listen.mouse.y
Use the simple isMouseDown
api or use the key press api for Mouse1
:
lib.listen.isMouseDown() // Only left click
lib.listen.isKey("Mouse1") // Left click
lib.listen.isKey("Mouse2") // Right click
For a simple check if a key is down:
lib.listen.isKey("a") // A
lib.listen.isKey("A") // Shift + A
// Check if multiple are down
lib.listen.isManyKeys("a", "b") // A and B
Checking when a key is first pressed is also easy:
lib.listen.onKeyDown("a") // True on the first frame "a" is pressed on