p5play Class
Look at the p5play reference pages before reading these docs.
Item Index
Methods
- animation
- background
- colorPal
- createCanvas
- createGroup deprecated
- createSprite deprecated
- createTiles deprecated
- delay
- drawSprites deprecated
- drawSprites deprecated
- fill
- getFPS
- getSpriteAt deprecated
- getSpritesAt deprecated
- loadAni
- loadAnimation
- loadImage
- play
- spriteArt
- stroke
- updateSprites deprecated
Methods
animation
-
ani
-
x
-
y
-
r
-
sX
-
sY
Displays an animation. Similar to the p5.js image function.
Parameters:
-
ani
SpriteAnimationAnimation to be displayed
-
x
Numberposition of the animation on the canvas
-
y
Numberposition of the animation on the canvas
-
r
Numberrotation of the animation
-
sX
Numberscale of the animation in the x direction
-
sY
Numberscale of the animation in the y direction
background
()
Just like the p5.js background function except it also accepts a color pallette code.
colorPal
-
c
-
palette
Gets a color from a color palette
Parameters:
-
c
StringA single character, a key found in the color palette object.
-
palette
Number | ObjectCan 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
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
Use of new Group()
is preferred.
Creates a new group of sprites.
Returns:
createTiles
()
deprecated
Use of new Tiles()
is preferred.
delay
-
millisecond
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:
A Promise that fulfills after the specified time.
Example:
async function startGame() { await delay(3000); }
drawSprites
()
deprecated
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
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
()
Just like the p5.js fill function except it also accepts a color pallette code.
getFPS
()
Number
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:
The current FPS
getSpriteAt
()
deprecated
Use world.getSpriteAt instead
getSpritesAt
()
deprecated
Use world.getSpritesAt instead
loadAni
()
SpriteAnimation
Alias for new SpriteAnimation()
Load animations in the preload p5.js function if you need to use them when your program starts.
Returns:
loadImage
-
url
-
[width]
-
[height]
-
[callback]
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
Awaitable function for playing sounds.
Parameters:
-
sound
p5.Sound
Returns:
Example:
await play(sound);
spriteArt
-
txt
-
scale
-
palette
Create pixel art images from a string. Each character in the input string represents a color value defined in the palette object.
Parameters:
-
txt
StringEach character represents a pixel color value
-
scale
NumberThe scale of the image
-
palette
Number | ObjectColor palette
Returns:
A p5.js Image
Example:
let str =
...yyyy .yybyybyy yyyyyyyyyy yybyyyybyy .yybbbbyy ...yyyy
;
let img = spriteArt(str);
stroke
()
Just like the p5.js stroke function except it also accepts a color pallette code.
updateSprites
()
deprecated
Deprecated. Use world.step and allSprites.update instead.
Properties
allSprites
Unknown
A group of all the sprites.
camera
Unknown
The default camera. Use this to pan and zoom the camera.
contro
Unknown
Get user input from game controllers.
frame
Unknown
deprecated
Deprecated, use the p5.js frameCount instead.
This property will be removed in v3.7.0
kb
Unknown
Get user input from the keyboard.
keyboard
Unknown
Alias for kb.
mouse
Unknown
Get user input from the mouse. Stores the state of the left, center, or right mouse buttons.
world
Unknown
The planck physics world. Use this to change gravity and offset the sprite's coordinate system.