Show:
Module: p5play

Methods

_isKeyInState
(
  • key
  • state
)
Boolean
private

Defined in lib/p5play.js:3771

Detects if a key is in the given state during the last cycle. Helper method encapsulating common key state logic; it may be preferable to call keyDown or other methods directly.

Parameters:

  • key Number | String

    Key code or character

  • state Number

    Key state to check against

Returns:

Boolean:

True if the key is in the given state

_isMouseButtonInState
(
  • buttonCode
  • state
)
Boolean
private

Defined in lib/p5play.js:3849

Detects if a mouse button is in the given state during the last cycle. Helper method encapsulating common mouse button state logic; it may be preferable to call mouseWentUp, etc, directly.

Parameters:

  • [buttonCode] Number optional

    Mouse button constant LEFT, RIGHT or CENTER

  • state Number

Returns:

Boolean:

True if the button was in the given state

_keyCodeFromAlias
(
  • alias
)
Number | Undefined
private

Defined in lib/p5play.js:3990

Given a string key alias (as defined in the KEY property above), look up and return the numeric JavaScript key code for that key. If a deprecated alias is passed (as defined in the KEY_DEPRECATIONS property) it will be mapped to a valid key code, but will also generate a warning about use of the deprecated alias.

Parameters:

  • alias !string
    • a case-insensitive key alias

Returns:

Number | Undefined:

a numeric JavaScript key code, or undefined if no key code matching the given alias is found.

_warn
(
  • message
)
private

Defined in lib/p5play.js:4039

Log a warning message to the host console, using native console.warn if it is available but falling back on console.log if not. If no console is available, this method will fail silently.

Parameters:

  • message !string
animation
(
  • anim
  • x
  • y
)

Defined in lib/p5play.js:3720

Displays an animation.

Parameters:

  • anim SpriteAnimation

    Animation to be displayed

  • x Number

    X coordinate

  • y Number

    Y coordinate

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

Defined in lib/p5play.js:3608

A Sprite is the main building block of p5play: 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.

Sprites are added to the allSprites group and given a depth value that puts it in front of all other sprites by default.

Using this method is equivalent to using the Sprite constructor.

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:

Sprite:

The new sprite instance

drawSprite
(
  • sprite
)

Defined in lib/p5play.js:3688

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

Parameters:

  • sprite Sprite

    Sprite to be displayed

drawSprites
(
  • group
)

Defined in lib/p5play.js:3668

Displays a Group of sprites. If no parameter is specified, draws all sprites in the sketch. The drawing order is determined by the Sprite property "depth"

Parameters:

  • [group] Group optional

    Group of Sprites to be displayed

getSprites () Array

Defined in lib/p5play.js:3645

Returns all the sprites in the sketch as an array

Returns:

Array:

Array of Sprites

keyDown
(
  • key
)
Boolean

Defined in lib/p5play.js:3759

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/p5play.js:3733

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/p5play.js:3746

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/p5play.js:3709

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

Parameters:

  • sprite Sprite

    Sprite to be displayed

loadSpriteSheet ()

Defined in lib/p5play.js:3699

Loads a Sprite Sheet. To be typically used in the preload() function of the sketch.

mouseDown
(
  • buttonCode
)
Boolean

Defined in lib/p5play.js:3801

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

Parameters:

  • [buttonCode] Number optional

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button is down

mouseUp
(
  • buttonCode
)
Boolean

Defined in lib/p5play.js:3813

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

Parameters:

  • [buttonCode] Number optional

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button is up

mouseWentDown
(
  • buttonCode
)
Boolean

Defined in lib/p5play.js:3837

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:

  • [buttonCode] Number optional

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button was just pressed

mouseWentUp
(
  • buttonCode
)
Boolean

Defined in lib/p5play.js:3825

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:

  • [buttonCode] Number optional

    Mouse button constant LEFT, RIGHT or CENTER

Returns:

Boolean:

True if the button was just released

removeSprite
(
  • sprite
)

Defined in lib/p5play.js:3633

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

Parameters:

  • sprite Sprite

    The sprite to be removed

updateSprites
(
  • updating
)

Defined in lib/p5play.js:4165

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/p5play.js:4020

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.

p5play will create and update a quadtree automatically.

Parameters:

  • use Boolean

    Pass true to enable, false to disable

Properties

allSprites

Group

Defined in lib/p5play.js:4069

A Group containing all the sprites in the sketch.

camera

Camera

Defined in lib/p5play.js:4101

The sketch camera automatically created at the beginning of a sketch. A camera facilitates scrolling and zooming for scenes extending beyond the canvas. A camera has a position, a zoom factor, and the mouse coordinates relative to the view.

In p5.js terms the camera wraps the whole drawing cycle in a transformation matrix but it can be disabled anytime during the draw cycle, for example to draw interface elements in an absolute position.

KEY

Object private

Defined in lib/p5play.js:3874

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

KEY_DEPRECATIONS

Object private

Defined in lib/p5play.js:3977

An object storing deprecated key aliases, which we still support but should be mapped to valid aliases and generate warnings.