Global

Members

allSprites :Group

A group that includes all the sprites.
Source:
Type:

camera :Camera

The default camera.
Source:
Type:

canvas :Canvas

HTML5 canvas element.
Source:
Type:

contro :Contro

For convenience, `contro` can be used to attempt to check the input states of `contros[0]` and won't throw errors if a controller isn't connected yet. By default it is set to a mock controller object which you can edit to test your game's input handling.
Source:
Type:

controllers :_Contros

Alias for contros
Source:
Type:

contros :_Contros

Array of game controllers.
Source:
Type:

kb :_Keyboard

Get user input from the keyboard.
Source:
Type:

keyboard :_Keyboard

Alias for kb.
Source:
Type:

loadAnimation

Alias for `new Ani()` Load animations in the `preload` function if you need to use them when your program starts.
Source:

loadImage

Loads an image. p5play caches images so that they're only loaded once, so multiple calls to `loadImage` with the same path will return the same image object. p5play also adds the image's url as a property of the image object.
Source:

log :function

Shortcut for console.log
Source:
Type:
  • function

mouse :_Mouse

Get user input from the mouse. Stores the state of the left, center, or right mouse buttons.
Source:
Type:

p5play :P5Play

Contains information about the sketch.
Source:
Type:

touches :Array:.<_Touch:>

An array of touch objects.
Source:
Type:

world :World

The physics world.
Source:
Type:

Methods

EmojiImage(emoji, textSize) → {p5.Image}

Creates a new image of an emoji, trimmed to the emoji's dimensions.
Source:
Parameters:
Name Type Description
emoji String
textSize Number
Returns:
Type:
p5.Image
emojiImage
Example
let img = new EmojiImage('🏀', 32);

animation(ani, x, y, r, sX, sY)

Displays an animation. Similar to the `image` function.
Source:
Parameters:
Name Type Description
ani Ani Animation to be displayed
x Number position of the animation on the canvas
y Number position of the animation on the canvas
r Number rotation of the animation
sX Number scale of the animation in the x direction
sY Number scale of the animation in the y direction

background()

Covers the canvas with a color or image. In p5play it can also accept a color palette code.
Source:

colorPal(c, palette) → {String}

Gets a color from a color palette.
Source:
Parameters:
Name Type Description
c String A single character, a key found in the color palette object.
palette Number | Object can be a palette object or number index in the system's palettes array.
Returns:
Type:
String
a hex color string

createCanvas() → {p5.Renderer}

Use of `new Canvas()` is preferred. Check the Canvas constructor for documentation. This function differs from `new Canvas()` because it returns a p5.Renderer object instead of the HTML5 canvas object itself.
Source:
Returns:
Type:
p5.Renderer
renderer object

createGroup() → {Group}

Use of `new Group()` is preferred. Creates a new group of sprites.
Deprecated:
  • Yes
Source:
Returns:
Type:
Group

createSprite() → {Sprite}

Use of `new Sprite()` is preferred. Creates a new sprite.
Deprecated:
  • Yes
Source:
Returns:
Type:
Sprite

createTiles()

Use of `new Tiles()` is preferred.
Deprecated:
  • Yes
Source:

delay(millisecond) → {Promise}

Delays code execution in an async function for the specified time. If no input is given, it waits until a new animation frame is ready to be drawn using the `window.requestAnimationFrame` function.
Source:
Parameters:
Name Type Description
millisecond Number
Returns:
Type:
Promise
A Promise that fulfills after the specified time.
Example
async function startGame() {
  await delay(3000);
}

fill()

Sets the color used to fill shapes. In p5play it can also accept a color palette code.
Source:

getFPS() → {Number}

FPS, amongst the gaming community, refers to how fast a computer can generate frames per second, not including the delay between when frames are actually shown on the screen. The higher the FPS, the better the game is performing. This function is used by the renderStats() function, which is the easiest way to get an approximation of your game's performance. But you should use your web browser's performance testing tools for accurate results.
Source:
Returns:
Type:
Number
The current FPS

play(sound) → {Promise}

Awaitable function for playing sounds.
Source:
Parameters:
Name Type Description
sound any
Returns:
Type:
Promise
Example
await play(sound);

renderStats(x, y)

Deprecated. Use `p5play.renderStats = true` instead.
Deprecated:
  • Yes
Source:
Parameters:
Name Type Description
x Number
y Number

resizeCanvas()

Use of `canvas.resize()` is preferred.
Source:

sleep(millisecond) → {Promise}

Delays code execution in an async function for the specified time. If no input is given, it waits until after a world step is completed.
Source:
Parameters:
Name Type Description
millisecond Number
Returns:
Type:
Promise
A Promise that fulfills after the specified time.
Example
async function startGame() {
  await sleep(3000);
}

spriteArt(txt, scale, palette) → {p5.Image}

Create pixel art images from a string. Each character in the input string represents a color value defined in the palette object.
Source:
Parameters:
Name Type Description
txt String each character represents a pixel color value
scale Number the scale of the image
palette Number | Object color palette
Returns:
Type:
p5.Image
A p5.Image object
Example
let str = `
...yyyy
.yybyybyy
yyyyyyyyyy
yybyyyybyy
.yybbbbyy
...yyyy`;

let img = spriteArt(str);

stroke()

Sets the color used to stroke an outline around a shape. In p5play it can also accept a color palette code.
Source: