Miscellaneous

Miscellaneous Funcions

getWindowWidth

Returns the width of your window

Returns

Returns: number The width in pixels

let width = getWindowWidth()

getWindowHeight

Returns the height of your window

Returns

number The height in pixels

let height = getWindowHeight()

getScreenSize

If you have already called makeGraphicsWindow, this will return the size of the graphics window you made. If you have not already called makeGraphicsWindow, then it returns the current resolution of the browser window.

Returns

array An array containing the width and height of the window or screen.

let [width, height] = getScreenSize()

setBackground

Sets the background color or image for your animation.

name
type
default
description

background*

object|array|string

-

The color or image to use as a background. If the background is null, then the background will not be erased between frames, so your moving object will leave trails (unless you erase them yourself).

Returns

nothing

setBackground("red")
setBackground([240, 230, 140])
setBackground(loadImage(require("./mybackground.jpg")))
setBackground(null)

setWindowTitle

Sets the title of the window.

name
type
default
description

title*

string

-

the title for the window

Returns

nothing

setWindowTitle("Cool Game")

getColorsList

Returns a list of the names of all of the built-in colors supported by this library.

Returns

array An array of strings, each of which is the name of a built-in color.

let colorlist = getColorsList()

getFontList

Returns an array of the names of all of the built-in Fonts supported by this library.

Returns

array An array of strings, each of which is the name of a built-in font.

let fontlist = getFontList()

sizeString

Computes the number of pixels needed to draw a string

name
type
default
description

text*

string

-

the text to display

size

number

30

the size of the letters in the text, in pixels

bold

boolean

false

true for bold, false for regular

italic

boolean

false

true for italic, false for regular

font

string

default system font

the name of the font to use - see getFontList to find out what fonts are available

Returns

nothing

let [width, height] = sizeString("score: ", 30)

saveScreen

Draws a single pixel.

name
type
default
description

filename*

string

'black'

The filename of the file in which to save the image. The format of the file will be determined by the filename extension.

Returns

nothing

saveScreen("screenshot.jpg")

getScreenPixel

Draws a single pixel.

name
type
default
description

x*

number

-

the x coordinate of the pixel

y*

number

-

the pixel coordinate of the point

Returns

array An array containing the color. The tuple will have 4 parts, for the red, green, blue, and opacity components of the color, each of which is a number between 0 and 255.

let [red, green, blue, opacity] = getScreenPixel(x,y)

Last updated