gamvas.mouse

Description

Information and functions for the mouse.

PLEASE NOTE

There are browsers that are not able to handle middle and right mouse buttons without problems.

Middle and rigth mouse button is successfully tested on current versions of

  • Chrome
  • Firefox
  • xxxterm
Summary
gamvas.mouseInformation and functions for the mouse.
Variables
LEFTDefines the left mouse button
MIDDLEDefines the middle mouse button
RIGHTDefines the right mouse button
Functions
isPressedCheck if a mouse button is pressed
getXReturns the x position of the mouse over the canvas.
getYReturns the y position of the mouse over the canvas.
getPositionReturns the position of the mouse as gamvas.Vector2D
exitEventreturn from a unhandled mouseevent on onMouse* functions

Variables

LEFT

LEFT: 0

Description

Defines the left mouse button

MIDDLE

MIDDLE: 1

Description

Defines the middle mouse button

RIGHT

RIGHT: 2

Description

Defines the right mouse button

Functions

isPressed

isPressed: function(k)

Description

Check if a mouse button is pressed

Returns

true/false

Example

if (gamvas.mouse.isPressed(gamvas.mouse.LEFT)) {
    alert('you have found your left mouse button');
}

getX

getX: function(ev)

Description

Returns the x position of the mouse over the canvas.

getY

getY: function(ev)

Description

Returns the y position of the mouse over the canvas.

getPosition

getPosition: function(ev)

Description

Returns the position of the mouse as gamvas.Vector2D

Note

The position is relative to the canvas, so 0/0 is the upper left corner and canvaswidth/canvasheight is the lower right corner.

To convert the canvas mouse position the the current states world use <gamvas.camera.toWorld> from this.camera of the current state

Returns

gamvas.Vector2D

exitEvent

exitEvent: function()

Description

return from a unhandled mouseevent on onMouse* functions

See

gamvas.State.onMouseDown gamvas.State.onMouseUp gamvas.State.onMouseMove

LEFT: 0
Defines the left mouse button
MIDDLE: 1
Defines the middle mouse button
RIGHT: 2
Defines the right mouse button
isPressed: function(k)
Check if a mouse button is pressed
getX: function(ev)
Returns the x position of the mouse over the canvas.
getY: function(ev)
Returns the y position of the mouse over the canvas.
getPosition: function(ev)
Returns the position of the mouse as gamvas.Vector2D
exitEvent: function()
return from a unhandled mouseevent on onMouse* functions
A 2D vector class
onMouseDown: function(button,
x,
y,
ev)
A mouse button was pressed
onMouseUp: function(button,
x,
y,
ev)
A mouse button was released
onMouseMove: function(x,
y,
ev)
The mouse was moved
Close