Show:
Module: p5.play
Parent Module: p5.play

Methods

animation
(
  • anim
  • x
  • y
)

Defined in lib/p5.play.js:211

Displays an animation.

Parameters:

  • anim Animation

    Animation to be displayed

  • x Number

    X coordinate

  • y Number

    Y coordinate

createSprite
(
  • x
  • y
  • width
  • height
)
Object

Defined in lib/p5.play.js:60

A Sprite is the main building block of p5.play: an element able to store images or animations with a set of properties such as position and visibility. A Sprite can have a collider that defines the active area to detect collisions or overlappings with other sprites and mouse interactions.

Parameters:

  • x Number

    Initial x coordinate

  • y Number

    Initial y coordinate

  • width Number

    Width of the placeholder rectangle and of the collider until an image or new collider are set

  • height Number

    Height of the placeholder rectangle and of the collider until an image or new collider are set

Returns:

Object:

The new sprite instance

drawSprite
(
  • sprite
)

Defined in lib/p5.play.js:189

Displays a Sprite. To be typically used in the main draw function.

Parameters:

  • sprite Sprite

    Sprite to be displayed

getSprites () Array

Defined in lib/p5.play.js:122

Returns all the sprites in the sketch as an array

Returns:

Array:

Array of Sprites

keyDown
(
  • key
)
Boolean

Defined in lib/p5.play.js:293

Detects if a key is currently pressed Like p5 keyIsDown but accepts strings and codes

Parameters:

  • key Number | String

    Key code or character

Returns:

Boolean:

True if the key is down

keyWentDown
(
  • key
)
Boolean

Defined in lib/p5.play.js:233

Detects if a key was pressed during the last cycle. It can be used to trigger events once, when a key is pressed or released. Example: Super Mario jumping.

Parameters:

  • key Number | String

    Key code or character

Returns:

Boolean:

True if the key was pressed

keyWentUp
(
  • key
)
Boolean

Defined in lib/p5.play.js:263

Detects if a key was released during the last cycle. It can be used to trigger events once, when a key is pressed or released. Example: Spaceship shooting.

Parameters:

  • key Number | String

    Key code or character

Returns:

Boolean:

True if the key was released

loadAnimation
(
  • sprite
)

Defined in lib/p5.play.js:200

Loads an animation. To be typically used in the preload() function of the sketch.

Parameters:

  • sprite Sprite

    Sprite to be displayed

mouseDown
(
  • button
)
Boolean

Defined in lib/p5.play.js:322

Detects if a mouse button is currently down Combines mouseIsPressed and mouseButton of p5

Parameters:

  • button Number

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button is down

mouseUp
(
  • button
)
Boolean

Defined in lib/p5.play.js:349

Detects if a mouse button is currently up Combines mouseIsPressed and mouseButton of p5

Parameters:

  • button Number

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button is up

mouseWentDown
(
  • button
)
Boolean

Defined in lib/p5.play.js:404

Detects if a mouse button was pressed during the last cycle. It can be used to trigger events once, to be checked in the draw cycle

Parameters:

  • button Number

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button was just pressed

mouseWentUp
(
  • button
)
Boolean

Defined in lib/p5.play.js:376

Detects if a mouse button was released during the last cycle. It can be used to trigger events once, to be checked in the draw cycle

Parameters:

  • button Number

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button was just released

removeSprite
(
  • sprite
)

Defined in lib/p5.play.js:85

Removes a Sprite from the sketch. The removed Sprite won't be drawn or updated anymore. Equivalent to Sprite.remove()

Parameters:

  • sprite Object

    Sprite to be removed

updateSprites
(
  • updating
)

Defined in lib/p5.play.js:97

Updates all the sprites in the sketch (position, animation...) it's called automatically at every draw(). It can be paused by passing a parameter true or false; Note: it does not render the sprites.

Parameters:

  • updating Boolean

    false to pause the update, true to resume

useQuadTree
(
  • use
)

Defined in lib/p5.play.js:573

Turns the quadTree on or off. A quadtree is a data structure used to optimize collision detection. It can improve performance when there is a large number of Sprites to be checked continuously for overlapping.

p5.play will create and update a quadtree automatically.

Parameters:

  • use Boolean

    Pass true to enable, false to disable

Properties

allSprites

Group

Defined in lib/p5.play.js:52

A Group containing all the sprites in the sketch.

KEY

Group

Defined in lib/p5.play.js:432

An object storing all useful keys for easy access Key.tab = 9