new MouseEventManager(scope)
Manages mouse 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 MouseEventManager looks at. |
- 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.mouse.buttonIsPressed()) {
myScreen.setScene(pause_menu);
}
});Methods
buttonIsPressed(button) → {Boolean}
Check if a button is currently pressed down
| Name | Type | Description |
|---|---|---|
button | String | The button you want to check |
- Source
if the button is pressed
- Type:
- Boolean
// see if the left button is pressed
if (myGame.mouse.buttonIsPressed("left")) {
// do something
}(package) destruct()
Destructs the event manager (clears events)
- Source
eventJustHappened(event, captureopt) → {Boolean}
Check if a mouse event just happened (eg a button press or scroll)
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
event | String | The event you want to check | ||
capture | Boolean | <optional> | false | Capture the event, and stop other checks from seeing it |
- Source
if the event just happened
- Type:
- Boolean
// See if the player clicked.
if (myScreen.mouse.eventJustHappened("click")) {
// do something
}getPosition() → {gameify.Vector2d}
Get the x and y position of the mouse cursor on the creen
- Source
The mouse position on the Screen
- Type:
- gameify.
Vector2d
if (myScreen.mouse.getPosition().x < 50) {
// do something
}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
setRecentEventTimeout(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
worldPosition() → {gameify.Vector2d}
Get the x and y position of the mouse cursor in the world
- Source
The mouse position in the world
- Type:
- gameify.
Vector2d