API
Contents
- 1 Simple Functions
- 1.1 clear();
- 1.2 drawCircle(x, y, radius);
- 1.3 drawLine(x1, y1, x2, y2);
- 1.4 drawRectangle (x, y, width, height);
- 1.5 fillCircle (x, y, radius);
- 1.6 fillRectangle (x, y, width, height);
- 1.7 print (text, x, y);
- 1.8 makeBackground();
- 1.9 loadImage(imageURL);
- 1.10 drawImage(image, x, y)
- 1.11 getMousePostion()
- 1.12 keyIsDown(keyCode)
- 1.13 run(move,draw,updateRate)
- 1.14 keyWentDown(keyCode)
- 2 Objects
Simple Functions
clear();
Clears the screen
drawCircle(x, y, radius);
Draws an unfilled circle with the center at x, y
drawLine(x1, y1, x2, y2);
Draws a line starting at x1, y1 and ending at x2, y2
drawRectangle (x, y, width, height);
Draws an unfilled rectangle with the top left corner at x, y.
fillCircle (x, y, radius);
Draws a filled circle with the center at x, y
fillRectangle (x, y, width, height);
Draws a filled rectangle with the top left corner at x, y.
print (text, x, y);
Draws text at x,y If x and y are not given, the text will appear below the last printed line.
makeBackground();
Turns the current contents of the screen into a background image that remains after a clear() call.
loadImage(imageURL);
Loads an Image from a url and returns an object that can be used for drawImage. The image download will begin immediately, but drawing the image will have no effect until the download has completed. This means if you try to draw an image immediately after a loadImage call it will most likely not appear since it has not had time to download.
drawImage(image, x, y)
Draws an image with the top left corner at x,y on the screen.
getMousePostion()
Returns an object with x and y fields indicating the current mouse pointer position;
keyIsDown(keyCode)
Returns true if the key indicated by keyCode is held down.
run(move,draw,updateRate)
This function expects move and draw to be functions. It will set up a timer and repeatedly call move() and draw() updateRate times a second.
keyWentDown(keyCode)
Returns true if the key indicated by keyCode was pressed since the last move() cycle of a program using run().
Objects
eventManager
The eventManager receives events from the hosting webpage and passes them out to attached listeners.
Programs can receive events by installing listeners with eventManager.addEventListener(eventName,eventFunction)
The events that can be received are
- mousedown
- mouseup
- mousemove
- keydown
- keyup
- batchnotify
The object passed to the event listener will not have the full details that may exist in the browser. It is a simple object with no methods and just a few of the standard fields transferred from the browser event.
inputManager
The input Manager tracks input events to provide a poll-able state. The functions getMousePostion(), keyIsDown(), and keyWentDown() access methods of inputManager with the same name.
Key down events are accumulated in a buffer and transferred to the keyWentDown buffer when inputManager.cycle() is called. The run(move,draw) function calls inputManager.cycle() before each move() call.