Skip to content
Jesper Sørensen edited this page Sep 7, 2014 · 1 revision

Class: Pointer

Pointer

A class that eases the use of mouse and touch, by providing functions for checking the current state of both.

new Pointer()

Constructor for the Pointer class

Source:

Methods

<private> calculateRoomPosition(vector) → {Math.Vector}

Converts a coordinate which is relative to the main canvas to a position in the room (based on the room's cameras)

Parameters:
Name Type Description
vector Math.Vector

A vector representing a position which is relative to the main canvas

Source:
Returns:

vector A vector representing the calculated position relative to the room

Type
Math.Vector

<private> checkPointer(pointers, state) → {boolean}

Checks the state of a pointer object

Parameters:
Name Type Description
pointers Object | Array.<Object>

A pointer object or an array of pointer objects to check the state of

state string

A state to check for "pressed", "released" or "down"

Source:
Returns:

Whether or not the pointer or one of the pointers has the provided state

Type
boolean

<private> findTouchNumber() → {number|boolean}

Finds the first available spot in the Pointer.touches-array, used for registering the touches as numbers from 0-9. In Google Chrome, each touch's identifier can be used directly since the numbers - starting from 0 - are reused, when the a touch is released. In Safari however each touch has a unique id (a humongous number), and a function (this) is therefore needed for identifying the touches as the numbers 0-9, which can be used in the Pointer.touches-array.

Source:
Returns:

The first available spot in the Pointer.touches-array where a new touch can be registered. If no spot is available, false is returned

Type
number | boolean

<private> getButtonType(button) → {string}

Returns a string representing the button type.

Parameters:
Name Type Description
button number

A pointer button constant representing the button

Source:
Returns:

A string representing the type of button ("mouse", "touch" or "any")

Type
string

isDown(button) → {Array.<Object>|boolean}

Checks if a mouse button or touch is currently down.

Parameters:
Name Type Description
button number

A pointer constant representing the pointer to check

Source:
Returns:

Returns an array containing the pointers that are currently down, or false if no pointers are down

Type
Array.<Object> | boolean

isPressed(button) → {Array.<Object>|boolean}

Checks if a mouse button or touch has just been pressed (between the last and the current frame).

Parameters:
Name Type Description
button number

A pointer constant representing the pointer to check

Source:
Returns:

Returns an array containing the pointers that have just been pressed, or false if no pressed pointers where detected

Type
Array.<Object> | boolean

isReleased(button) → {Array.<Object>|boolean}

Checks if a mouse button or touch just been released (between the last and the current frame).

Parameters:
Name Type Description
button number

A pointer constant representing the pointer to check

Source:
Returns:

Returns an array containing the pointers that have just been released, or false if no released pointers where detected

Type
Array.<Object> | boolean

mouseHasMoved() → {boolean}

Checks if the mouse has been moved between the last and the current frame.

Source:
Returns:

True if the pointer has been moved, false if not

Type
boolean

<private> onMouseDown(event)

Registers every onmousedown event to the Mouse object.

Parameters:
Name Type Description
event MouseEvent

Event object passed by the onmousedown event

Source:

<private> onMouseMove(event)

Registers every onmousemove event to the Mouse object.

Parameters:
Name Type Description
event MouseEvent

Event object passed by the onmousemove event

Source:

<private> onMouseUp(event)

Registers every onmouseup event to the Mouse object.

Parameters:
Name Type Description
event MouseEvent

Event object passed by the onmouseup event

Source:

<private> onTouchEnd(event)

Registers every ontouchend event to the Mouse object.

Parameters:
Name Type Description
event TouchEvent

Event object passed by the ontouchend event

Source:

<private> onTouchMove(event)

Registers every ontouchmove event to the Mouse object.

Parameters:
Name Type Description
event TouchEvent

Event object passed by the ontouchmove event

Source:

<private> onTouchStart(event)

Registers every ontouchstart event to the Mouse object.

Parameters:
Name Type Description
event TouchEvent

Event object passed by the ontouchstart event

Source:

outside() → {boolean}

Checks if the mouse pointer is outside the game arena.

Source:
Returns:

True if the pointer is outside, false if not

Type
boolean

release(button) → {boolean}

Releases a button, and thereby prevents the button from being detected as "pressed" by the isPressed function. This function is very useful for preventing one button press from having multiple effects inside the game. For instance on buttons that are placed on top of each other.

Parameters:
Name Type Description
button number

The button to release

Source:
Returns:

True if the button has now been released, false if the button was not already pressed

Type
boolean

<private> resetCursor()

Resets the mouse cursor, automatically called by the engine before each frame i executed, unless engine.resetCursorOnEachFrame is set to false

Source:

setCursor(A)

Sets the mouse cursor for the arena. By default the mouse cursor will be reset on each frame (this can be changed with the "resetCursorOnEachFrame" engine option) Please be aware that not all images can be used as cursor. Not all sizes and formats are supported by all browsers.

Parameters:
Name Type Description
A string

resource string, image path string or css cursor of the cursor

Source:

shapeIsDown(button, shape, outside) → {Array.<Object>|boolean}

Checks if an area defined by a geometric shape, or its outside, is down (currently clicked by mouse or touch). The shape can be any geometric object that has a contains function (Rectangle, Polygon).

Parameters:
Name Type Description
button button

A pointer constant representing the pointers to check

shape Math.Rectangle | Math.Polygon | Math.Circle

A geometric shape defining the area to check

outside boolean

[Whether or not to check the outside of the specified area]

Source:
Returns:

An array containing the pointers that are currently pressing the shape, or false if no pointers inside the shape were detected

Type
Array.<Object> | boolean

shapeIsHovered(shape, outside) → {boolean}

Checks if an area defined by a geometric shape, or its outside, is hovered by the mouse pointer. The shape can be any geometric object that has a contains function (Rectangle, Polygon).

Parameters:
Name Type Description
shape Math.Rectangle | Math.Polygon | Math.Circle

A geometric shape defining the area to check

outside boolean

[Whether or not to check the outside of the specified area]

Source:
Returns:

True if the shape if hovered, false if not

Type
boolean

shapeIsPressed(button, shape, outside) → {Array.<Object>|boolean}

Checks if an area defined by a geometric shape, or its outside, has just been pressed (between the last and the current frame). The shape can be any geometric object that has a contains function (Rectangle, Polygon).

Parameters:
Name Type Description
button button

A pointer constant representing the pointers to check

shape Math.Rectangle | Math.Polygon | Math.Circle

A geometric shape defining the area to check

outside boolean

[Whether or not to check the outside of the specified area]

Source:
Returns:

An array containing the pointers that have pressed the shape, or false if no presses inside the shape were detected

Type
Array.<Object> | boolean

shapeIsReleased(button, shape, outside) → {Array.<Object>|boolean}

Checks if an area defined by a geometric shape, or its outside, has just been released (between the last and the current frame). The shape can be any geometric object that has a contains function (Rectangle, Polygon).

Parameters:
Name Type Description
button button

A pointer constant representing the pointers to check

shape Math.Rectangle | Math.Polygon | Math.Circle

A geometric shape defining the area to check

outside boolean

[Whether or not to check the outside of the specified area]

Source:
Returns:

An array containing the pointers that have released the shape, or false if no releases inside the shape were detected

Type
Array.<Object> | boolean

Generated with wicked.
Clone this wiki locally