Add Events
parent
85677fd03f
commit
adcff5c3a3
|
@ -0,0 +1,65 @@
|
||||||
|
# Global Events
|
||||||
|
## Init
|
||||||
|
```js
|
||||||
|
function init() {
|
||||||
|
// Your Code
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Is called as soon as the browser page is prepared, exactly one frame before the first `tick()` execution.
|
||||||
|
|
||||||
|
## Tick
|
||||||
|
```js
|
||||||
|
function tick() {
|
||||||
|
// Your Code
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Is called on every "render tick". Interval is defined using the `FPS` configuration variable. `Time between ticks = 1000/FPS ms`.
|
||||||
|
|
||||||
|
When `PAUSED` is set to `true` execution of this function is paused until `PAUSED` is set back to `false`.
|
||||||
|
|
||||||
|
# Mouse Events
|
||||||
|
## On Mouse Move
|
||||||
|
```js
|
||||||
|
function onMouseMove(x, y) {
|
||||||
|
// Your Code
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Is called whenever a `mousemove` event is recieved somewhere on the page, not limited to the canvas.
|
||||||
|
|
||||||
|
`x`and `y` contain the coordinates of the mouse pointer, relative to the position of the canvas (`x = 0, y = 0` being top left).
|
||||||
|
|
||||||
|
## Mouse Button Events
|
||||||
|
```js
|
||||||
|
function onMouseDown(x, y, button) {
|
||||||
|
// Your Code
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseUp(x, y, button) {
|
||||||
|
// Your Code
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Are called whenever a `mousedown` or `mouseup` event, respectively, is recieved in the document. `x` and `y` are the coordinates of the mouse pointer, relative to the position of the canvas. `button` contains an integer between and including 0 and 2, defining the mouse button that was clicked or released (`0 = Left Mouse Button`, `1 = Middle Mouse Button`, `2 = Right Mouse Button`)
|
||||||
|
|
||||||
|
## Touch Support
|
||||||
|
|
||||||
|
All Mouse Events also work using touchscreen devices. A touch is always treated as a Left Mouse Button (`button = 0`).
|
||||||
|
|
||||||
|
Multitouch is not supported.
|
||||||
|
|
||||||
|
# Key Events
|
||||||
|
```js
|
||||||
|
function onKeyDown(e) {
|
||||||
|
// Your Code
|
||||||
|
}
|
||||||
|
|
||||||
|
function onKeyUp(e) {
|
||||||
|
// Your Code
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Are called whenever a `keydown` or `keyup` event, respectively, is recieved in the document. `e` is the event, the way it is passed from the document event handler.
|
||||||
|
|
Reference in New Issue