new KeyboardEventManager(scope)
Manages keyboard events. One is created automatically for every screen, you can access it as shown in the example.
| Name | Type | Description |
|---|---|---|
scope | HTMLElement | What parts of the screen the KeyboardEventManager looks for. |
- Source
// make a new screen and scene
let myScreen = new gameify.Screen(document.querySelector("#my-canvas"), 600, 400);
let myScene = new gameify.Scene(myScreen);
myScene.onUpdate(() => {
if (myScreen.keyboard.keyIsPressed("Escape")) {
myScreen.setScene(pause_menu);
}
});Methods
(package) destruct()
Destructs the event manager (clears events)
- Source
forceClearPressedKeys()
Force clear pressed keys
- Source
keyIsPressed(key) → {Boolean}
Check if a key is currently pressed down
| Name | Type | Description |
|---|---|---|
key | String | What key do you want to check |
- Source
if the key is pressed down
- Type:
- Boolean
// see if the right arrow is pressed
if (myGame.keyboard.keyIsPressed("Right")) {
// set the player motion
player.velocity.x = 5;
}keyWasJustPressed(key) → {Boolean}
Check if a key was just pressed and let up
| Name | Type | Description |
|---|---|---|
key | String | What key do you want to check |
- Source
if the key was just pressed
- Type:
- Boolean
// See if the player pressed the Escape key.
if (myScreen.keyboard.keyWasJustPressed("Escape")) {
myScreen.setScene(mainMenu);
}(package) makeKeyNicer(key) → {String}
Makes pressed keys nicer, for simpler queries (KeyH --> H)
| Name | Type | Description |
|---|---|---|
key | String | The key to make nicer |
- Source
The input key, with extra text stripped away.
- Type:
- String
onFirstFocus(callback)
Run a callback when the game is first focused (Useful for starting audio, etc)
| Name | Type | Description |
|---|---|---|
callback | function | The callback to run |
- Source
setCaptureScope(scope)
Changes the scope that the KeyboardInputManager looks at
| Name | Type | Description |
|---|---|---|
scope | HTMLElement | What parts of the screen the KeyboardEventManager looks for. |
- Source
setJustPressedTimeout(timeout)
Sets how long before "just pressed" keys are removed from the just pressed list. By default, keys are removed from the list after one frame.
| Name | Type | Description |
|---|---|---|
timeout | Number | How many frames/updates keys should be considered "just pressed" |
- Source
(package) setup()
Sets up the event manager.
- Source