gameify. MouseEventManager

new MouseEventManager(scope)

Manages mouse events. One is created automatically for every screen, you can access it as shown in the example.

Parameters:
NameTypeDescription
scopeHTMLElement

What parts of the screen the MouseEventManager looks at.

Example
// 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

Parameters:
NameTypeDescription
buttonString

The button you want to check

Returns:

if the button is pressed

Type: 
Boolean
Example
// see if the left button is pressed
if (myGame.mouse.buttonIsPressed("left")) {
    // do something
}

(package) destruct()

Destructs the event manager (clears events)

eventJustHappened(event, captureopt) → {Boolean}

Check if a mouse event just happened (eg a button press or scroll)

Parameters:
NameTypeAttributesDefaultDescription
eventString

The event you want to check

captureBoolean<optional>
false

Capture the event, and stop other checks from seeing it

Returns:

if the event just happened

Type: 
Boolean
Example
// 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

Returns:

The mouse position on the Screen

Type: 
gameify.Vector2d
Example
if (myScreen.mouse.getPosition().x < 50) {
    // do something
}

setCaptureScope(scope)

Changes the scope that the KeyboardInputManager looks at

Parameters:
NameTypeDescription
scopeHTMLElement

What parts of the screen the KeyboardEventManager looks for.

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.

Parameters:
NameTypeDescription
timeoutNumber

How many frames/updates keys should be considered "just pressed"

(package) setup()

Sets up the event manager.

worldPosition() → {gameify.Vector2d}

Get the x and y position of the mouse cursor in the world

Returns:

The mouse position in the world

Type: 
gameify.Vector2d