Members
pressedKeys :Array.<any>
- Source:
Type:
- Array.<any>
Example
if (pressedKeys.indexOf(Keyboard.SPACE) > -1) {
alert('you are pressing space!');
}
Methods
add(elem)
- Source:
Add an element to the graphics instance.
Example
let circle = new Circle(20);
add(circle);
Parameters:
Name | Type | Description |
---|---|---|
elem |
Thing | A subclass of Thing to be added to the graphics instance. |
clear()
- Source:
Clear the console.
deviceMotionMethod(fn)
- Source:
Assign a function as a callback for device motion events.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered device motion events. |
deviceOrientationMethod(fn)
- Source:
Assign a function as a callback for device orientation events.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on device orientation events. |
elementExistsWithParameters(params) → {boolean}
- Source:
Check if an element exists with the given paramenters.
Parameters:
Name | Type | Description |
---|---|---|
params |
object | Dictionary of parameters for the object. Includes x, y, heigh, width, color, radius, label and type. |
Returns:
- Type
- boolean
getDistance(x1, y1, x2, y2) → {number}
- Source:
Get the distance between two points, (x1, y1) and (x2, y2)
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | |
y1 |
number | |
x2 |
number | |
y2 |
number |
Returns:
Distance between the two points.
- Type
- number
getElementAt(x, y) → {Thing|null}
- Source:
Get an element at a specific point.
If several elements are present at the position, return the one put there first.
Example
let circle = new Circle(20);
circle.setPosition(100, 100);
add(circle);
getElementAt(100, 100) === circle;
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of a point to get element at. |
y |
number | The y coordinate of a point to get element at. |
Returns:
The object at the point (x, y), if there is one (else null).
- Type
- Thing | null
getElements() → {Array.<Thing>}
- Source:
Get all living elements.
Returns:
- Type
- Array.<Thing>
getElementsAt(x, y) → {Array.<Thing>}
- Source:
Get all elements at a specific point.
Example
let circle = new Circle(20);
circle.setPosition(100, 100);
add(circle);
let rectangle = new Rectangle(30, 30);
rectangle.setPosition(80, 80);
add(rectangle);
getElementsAt(100, 100)[1] === rectangle;
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of a point to get element at. |
y |
number | The y coordinate of a point to get element at. |
Returns:
The objects at the point (x, y).
- Type
- Array.<Thing>
getHeight() → {float}
- Source:
Get the height of the entire graphics canvas.
Example
if (getHeight() > 200) {
alert('The canvas is taller than 200 pixels!');
}
Returns:
The height of the canvas.
- Type
- float
getWidth() → {float}
- Source:
Get the width of the entire graphics canvas.
Example
if (getWidth() > 200) {
alert('The canvas is wider than 200 pixels!');
}
Returns:
The width of the canvas.
- Type
- float
isKeyPressed(keyCode) → {boolean}
- Source:
Check if a key is currently pressed
Example
if (isKeyPressed(Keyboard.letter('a'))) {
alert('Youre currently pressing A!');
}
Parameters:
Name | Type | Description |
---|---|---|
keyCode |
integer | Key code of key being checked. |
Returns:
Whether or not that key is being pressed.
- Type
- boolean
keyDownMethod(fn)
- Source:
Assign a function as a callback for keydown events.
Example
keyDownMethod(e => {
if (e.keyCode === Keyboard.letter('A')) {
alert('You just pushed the a key!');
}
})
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on keydown events. |
keyUpMethod(fn)
- Source:
Assign a function as a callback for key up events.
Example
keyUpMethod(e => {
if (e.keyCode === Keyboard.letter('A')) {
alert('You just lifted the a key!');
}
})
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on key up events. |
map(value, start1, end1, start2, end2) → {number}
- Source:
Maps a value from one range to another.
Example
// maps the sine of 1 from the range of sine (-1, 1) to the range (0, getHeight());
map(Math.sin(1), -1, 1, 0, getHeight());
Parameters:
Name | Type | Description |
---|---|---|
value |
number | Value to remap to a range |
start1 |
number | Lower bound of the current range |
end1 |
number | Upper bound of the current range |
start2 |
number | Lower bound of the desired range |
end2 |
number | Upper bound of the desired range |
Returns:
- Type
- number
mouseClickMethod(fn)
- Source:
Assign a function as a callback for click (mouse down, mouse up) events.
Example
mouseClickMethod(e => {
alert('You just clicked at ' + e.getX() + ', ' + e.getY());
});
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on click events. |
mouseDownMethod(fn)
- Source:
Assign a function as a callback for mouse down events.
Example
mouseDownMethod(e => {
alert('You depressed your mouse button at ' + e.getX() + ', ' + e.getY());
});
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on mouse down. |
mouseDragMethod(fn)
- Source:
Assign a function as a callback for drag events.
Example
mouseDragMethod(e => {
alert('You dragged your mouse to' + e.getX() + ', ' + e.getY());
});
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on drag events. |
mouseMoveMethod(fn)
- Source:
Assign a function as a callback for mouse move events.
Example
mouseMoveMethod(e => {
alert('You moved your mouse to ' + e.getX() + ', ' + e.getY());
});
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on mouse move events. |
mouseUpMethod(fn)
- Source:
Assign a function as a callback for mouse up events.
Example
mouseUpMethod(e => {
alert('You lifted your mouse button at ' + e.getX() + ', ' + e.getY());
});
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | A callback to be triggered on mouse up events. |
print(…args)
- Source:
Print a value to the console.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
any |
<repeatable> |
Anything to print. |
println(value)
- Source:
Print a value to the console, followed by a newline character.
Parameters:
Name | Type | Description |
---|---|---|
value |
any | The value to print. |
readBoolean(str) → {str}
- Source:
Read a bool from the user.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the readBoolean prompt.
- Type
- str
(async) readBooleanAsync(str) → {Promise.<boolean>}
- Source:
Read a bool from the user asynchronously.
This will receive input via the Console's configured Console#onInput function, which by default
will return a Promise that resolves with the result of using `window.prompt`, which will
block the browser.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the onPrompt function if it's a boolean, or 0.
- Type
- Promise.<boolean>
readFloat(str) → {str}
- Source:
Read a float from the user.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the readFloat prompt.
- Type
- str
(async) readFloatAsync(str) → {Promise.<number>}
- Source:
Read a float from the user asynchronously.
This will receive input via the Console's configured Console#onInput function, which by default
will return a Promise that resolves with the result of using `window.prompt`, which will
block the browser.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the onPrompt function if it's a float, or 0.
- Type
- Promise.<number>
readInt(str) → {str}
- Source:
Read an int with our special parseInt function which doesnt allow floats, even
though they are successfully parsed as ints.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the readInt prompt.
- Type
- str
(async) readIntAsync(str) → {Promise.<number>}
- Source:
Read an int from the user asynchronously.
This will receive input via the Console's configured Console#onInput function, which by default
will return a Promise that resolves with the result of using `window.prompt`, which will
block the browser.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the onPrompt function if it's an int, or 0.
- Type
- Promise.<number>
readLine(str) → {str}
- Source:
Read a line from the user.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the readLine prompt.
- Type
- str
(async) readLineAsync(str) → {Promise.<string>}
- Source:
Read a line asynchronously from the user.
This will receive input via the Console's configured Console#onInput function, which by default
will return a Promise that resolves with the result of using `window.prompt`, which will
block the browser.
Parameters:
Name | Type | Description |
---|---|---|
str |
str | A message associated with the modal asking for input. |
Returns:
The result of the prompt.
- Type
- Promise.<string>
remove(elem)
- Source:
Remove a specific element from the canvas.
Parameters:
Name | Type | Description |
---|---|---|
elem |
Thing | The element to be removed from the canvas. |
removeAll()
- Source:
Remove all elements from the canvas.
Example
add(new Circle(10));
add(new Rectangle(30, 30));
removeAll();
resetAllTimers()
- Source:
Resets all the timers to time 0.
rotatePointAboutPosition(point, origin, angle) → {Array.<number>}
- Source:
Rotate a point defined by an [x, y] pair around another point defined by an [x, y] pair by
an angle in radians.
Example
let center = [100, 100];
let point = [20, 30];
let rotated = rotatePointAboutPosition(center, point, Math.PI / 2);
Parameters:
Name | Type | Description |
---|---|---|
point |
Array.<number> | [x, y] of the point to rotate |
origin |
Array.<number> | [x, y] point of rotation |
angle |
number | angle in radians |
Returns:
- [x, y] rotated point
- Type
- Array.<number>
setBackgroundColor(color)
- Source:
Set the background color of the canvas.
Parameters:
Name | Type | Description |
---|---|---|
color |
Color | The desired color of the canvas. |
setFullscreen()
- Source:
Set the canvas to take up the entire parent element
setSize(w, h)
- Source:
Set the size of the canvas.
Parameters:
Name | Type | Description |
---|---|---|
w |
number | Desired width of the canvas. |
h |
number | Desired height of the canvas. |
setTimer(fn, time, data, name)
- Source:
Create a new timer.
Manager#setTimer
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | Function to be called at intervals. |
time |
integer | Time interval to call function `fn` |
data |
dictionary | Any data associated with the timer. |
name |
string | Name of this timer. |
stopAllTimers()
- Source:
Stop all timers.
waitForClick()
- Source:
- Deprecated:
- Yes
Record a click.
This will cause all timers to be postponed until a click event happens.