Members
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:
loadAnimation
Alias for `new Ani()`
Load animations in the `preload` function if you need to use
them when your program starts.
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.
mouse :_Mouse
Get user input from the mouse.
Stores the state of the left, center, or right mouse buttons.
Type:
Methods
EmojiImage(emoji, textSize) → {p5.Image}
Creates a new image of an emoji, trimmed to the emoji's dimensions.
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.
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.
colorPal(c, palette) → {String}
Gets a color from a color palette.
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.
Returns:
- Type:
-
p5.Renderer
renderer object
createGroup() → {Group}
Use of `new Group()` is preferred.
Creates a new group of sprites.
Returns:
- Type:
-
Group
createSprite() → {Sprite}
Use of `new Sprite()` is preferred.
Creates a new sprite.
Returns:
- Type:
-
Sprite
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.
Parameters:
Name | Type | Description |
---|---|---|
millisecond |
Number
|
Returns:
- Type:
-
Promise
A Promise that fulfills after the specified time.
Example
async function startGame() {
await delay(3000);
}
drawFrame()
p5play runs this function 60 times per second by default.
Put drawing code in this function, which should run after
input handling, game logic, and physics simulation.
- Source:
fill()
Sets the color used to fill shapes.
In p5play it can also accept a color palette code.
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.
Parameters:
Name | Type | Description |
---|---|---|
sound |
any
|
Returns:
- Type:
-
Promise
Example
await play(sound);
sleep(millisecond) → {Promise}
Delays code execution in an async function for the specified time.
If no input is given, it waits until after a physics update is completed.
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.
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.
update()
p5play runs this function 60 times per second by default.
Put input handling and game logic code in this function, which
should run before physics simulation and drawing.
- Source: