API Docs for: 3
Show:

p5play Class

Defined in: v3/p5play.js:5929

Look at the p5play reference pages before reading these docs.

https://p5play.org/learn

Methods

animation

(
  • ani
  • x
  • y
  • r
  • sX
  • sY
)

Defined in v3/p5play.js:6386

Displays an animation. Similar to the p5.js image function.

Parameters:

  • ani SpriteAnimation

    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

()

Defined in v3/p5play.js:6686

Just like the p5.js background function except it also accepts a color pallette code.

colorPal

(
  • c
  • palette
)

Defined in v3/p5play.js:6226

Gets a color from a color palette

Parameters:

  • 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:

a hex color string for use by p5.js functions

createCanvas

(
  • width|ratio
  • height
)

Defined in v3/p5play.js:6509

Use of new Canvas() is preferred.

p5play adds some extra functionality to the p5.js createCanvas function.

In p5play, a canvas can be created with an aspect ratio in the format width:height. For example new Canvas('16:9') will create the largest possible canvas with a 16:9 aspect ratio.

This function also disables the default keydown responses for the arrow keys, slash, and spacebar. This is to prevent the browser from scrolling the page when the user is playing a game using common keyboard commands.

Parameters:

  • width|ratio Number
  • height Number

createGroup

() Group deprecated

Defined in v3/p5play.js:6354

Use of new Group() is preferred.

Creates a new group of sprites.

Returns:

createSprite

() Sprite deprecated

Defined in v3/p5play.js:6341

Use of new Sprite() is preferred.

Creates a new sprite.

Returns:

createTiles

() deprecated

Defined in v3/p5play.js:5937

Use of new Tiles() is preferred.

delay

(
  • millisecond
)
Promise

Defined in v3/p5play.js:6402

Delay code execution in an async function for the specified time or if no input parameter is given, it waits for the next possible animation frame.

Parameters:

  • millisecond Number

Returns:

Promise:

A Promise that fulfills after the specified time.

Example:

async function startGame() { await delay(3000); }

drawSprites

() deprecated

Defined in v3/p5play.js:6310

Deprecated, use sprite.draw() instead.

allSprites.draw() is run automatically at the end of the p5.js draw loop, unless a sprite or group is drawn separately within the draw loop.

drawSprites

() deprecated

Defined in v3/p5play.js:6325

Deprecated, use group.draw() instead.

allSprites.draw() is run automatically at the end of the p5.js draw loop, unless a sprite or group is drawn separately within the draw loop.

fill

()

Defined in v3/p5play.js:6704

Just like the p5.js fill function except it also accepts a color pallette code.

getFPS

() Number

Defined in v3/p5play.js:6971

Use this function to performance test your game code. FPS, amongst the gaming community, refers to how many frames a game could render per second, not including the delay between when frames are shown on the screen. The higher the FPS, the better the game is performing.

Returns:

Number:

The current FPS

getSpriteAt

() deprecated

Defined in v3/p5play.js:6020

Use world.getSpriteAt instead

getSpritesAt

() deprecated

Defined in v3/p5play.js:6010

Use world.getSpritesAt instead

loadAni

() SpriteAnimation

Defined in v3/p5play.js:6367

Alias for new SpriteAnimation()

Load animations in the preload p5.js function if you need to use them when your program starts.

Returns:

loadAnimation

() SpriteAnimation

Defined in v3/p5play.js:6376

Alias for new SpriteAnimation()

Returns:

loadImage

(
  • url
  • [width]
  • [height]
  • [callback]
)

Defined in v3/p5play.js:6746

Just like the p5.js loadImage function except it also caches images so that they are only loaded once. Multiple calls to loadImage with the same path will return the same image object. It also adds the image's url as a property of the image object.

Parameters:

  • url String
  • [width] Number optional
  • [height] Number optional
  • [callback] Function optional

play

(
  • sound
)
Promise

Defined in v3/p5play.js:6434

Awaitable function for playing sounds.

Parameters:

  • sound p5.Sound

Returns:

Promise:

Example:

await play(sound);

spriteArt

(
  • txt
  • scale
  • palette
)

Defined in v3/p5play.js:6250

Create pixel art images from a string. Each character in the input string represents a color value defined in the palette object.

Parameters:

  • txt String

    Each character represents a pixel color value

  • scale Number

    The scale of the image

  • palette Number | Object

    Color palette

Returns:

A p5.js Image

Example:

let str = ...yyyy .yybyybyy yyyyyyyyyy yybyyyybyy .yybbbbyy ...yyyy;

let img = spriteArt(str);

stroke

()

Defined in v3/p5play.js:6722

Just like the p5.js stroke function except it also accepts a color pallette code.

updateSprites

() deprecated

Defined in v3/p5play.js:5998

Deprecated. Use world.step and allSprites.update instead.

Properties

allSprites

Unknown

Defined in v3/p5play.js:6918

A group of all the sprites.

camera

Unknown

Defined in v3/p5play.js:6943

The default camera. Use this to pan and zoom the camera.

contro

Unknown

Defined in v3/p5play.js:6966

Get user input from game controllers.

frame

Unknown deprecated

Defined in v3/p5play.js:6933

Deprecated, use the p5.js frameCount instead.

This property will be removed in v3.7.0

kb

Unknown

Defined in v3/p5play.js:6956

Get user input from the keyboard.

keyboard

Unknown

Defined in v3/p5play.js:6961

Alias for kb.

mouse

Unknown

Defined in v3/p5play.js:6950

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

world

Unknown

Defined in v3/p5play.js:6925

The planck physics world. Use this to change gravity and offset the sprite's coordinate system.