From d4cb2b110174205d04e290fe81eb22d75d77dd39 Mon Sep 17 00:00:00 2001 From: Quinton Ashley Date: Tue, 12 Sep 2023 21:07:26 -0500 Subject: [PATCH] 1.6.4 --- docs/-_Contro.html | 2 +- docs/-_Contros.html | 4 +- docs/-_KeyBoard.html | 2 +- docs/-_Mouse.html | 2 +- docs/-_SpriteMouse.html | 2 +- docs/Camera.html | 2 +- docs/Canvas.html | 2 +- docs/DistanceJoint.html | 2 +- docs/GlueJoint.html | 2 +- docs/Group.html | 3508 +++++++++++- docs/GroupSprite.html | 170 + docs/HingeJoint.html | 2 +- docs/InputDevice.html | 2 +- docs/Joint.html | 2 +- docs/P5Play.html | 2 +- docs/RopeJoint.html | 2 +- docs/SliderJoint.html | 2 +- docs/Sprite.html | 10560 +++++++++++++++++++++++++++++++++++- docs/SpriteAnimation.html | 2 +- docs/Subgroup.html | 170 + docs/Tiles.html | 2 +- docs/WheelJoint.html | 2 +- docs/World.html | 2 +- docs/global.html | 2 +- docs/index.html | 2 +- docs/p5play.js.html | 16 +- package.json | 5 +- v3/p5play.d.ts | 4 - v3/p5play.js | 14 +- v3/p5play.min.js | 2 +- 30 files changed, 14319 insertions(+), 174 deletions(-) create mode 100644 docs/GroupSprite.html create mode 100644 docs/Subgroup.html diff --git a/docs/-_Contro.html b/docs/-_Contro.html index 2ced2c8f..918fe196 100644 --- a/docs/-_Contro.html +++ b/docs/-_Contro.html @@ -171,7 +171,7 @@

new _Contro
- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/-_Contros.html b/docs/-_Contros.html index df339ce3..1875df2d 100644 --- a/docs/-_Contros.html +++ b/docs/-_Contros.html @@ -105,7 +105,7 @@

new _Contros<
Source:
@@ -189,7 +189,7 @@

Classes


- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/-_KeyBoard.html b/docs/-_KeyBoard.html index 6624b5ae..61834aec 100644 --- a/docs/-_KeyBoard.html +++ b/docs/-_KeyBoard.html @@ -172,7 +172,7 @@

new _KeyBoar
- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/-_Mouse.html b/docs/-_Mouse.html index d546c6b2..ee423eac 100644 --- a/docs/-_Mouse.html +++ b/docs/-_Mouse.html @@ -951,7 +951,7 @@

Returns:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/-_SpriteMouse.html b/docs/-_SpriteMouse.html index b9984f1b..3f6d6841 100644 --- a/docs/-_SpriteMouse.html +++ b/docs/-_SpriteMouse.html @@ -485,7 +485,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/Camera.html b/docs/Camera.html index 0d3eb63a..a70e9f7a 100644 --- a/docs/Camera.html +++ b/docs/Camera.html @@ -1026,7 +1026,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/Canvas.html b/docs/Canvas.html index 83954ba9..00e19728 100644 --- a/docs/Canvas.html +++ b/docs/Canvas.html @@ -800,7 +800,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/DistanceJoint.html b/docs/DistanceJoint.html index 8e3fc1c4..4520d8aa 100644 --- a/docs/DistanceJoint.html +++ b/docs/DistanceJoint.html @@ -244,7 +244,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/GlueJoint.html b/docs/GlueJoint.html index f616fa18..a3ddbd82 100644 --- a/docs/GlueJoint.html +++ b/docs/GlueJoint.html @@ -243,7 +243,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/Group.html b/docs/Group.html index b075f794..157fa614 100644 --- a/docs/Group.html +++ b/docs/Group.html @@ -24,7 +24,7 @@
@@ -120,7 +120,7 @@

new GroupSource:
@@ -234,7 +234,7 @@

amountSource:
@@ -308,7 +308,7 @@

aniSource:
@@ -382,7 +382,7 @@

animationSource:
@@ -456,7 +456,7 @@

anisSource:
@@ -530,7 +530,7 @@

imageSource:
@@ -604,7 +604,7 @@

imgSource:
@@ -684,7 +684,7 @@

applyForce<
Source:
@@ -763,7 +763,7 @@

apply
Source:
@@ -842,7 +842,7 @@

applyTorqu
Source:
@@ -921,7 +921,7 @@

attractToSource:
@@ -1005,7 +1005,7 @@

collidedSource:
@@ -1214,7 +1214,7 @@

collidesSource:
@@ -1400,7 +1400,7 @@

collidingSource:
@@ -1612,7 +1612,7 @@

cullSource:
@@ -1926,7 +1926,7 @@

drawSource:
@@ -2005,7 +2005,7 @@

moveSource:
@@ -2084,7 +2084,7 @@

moveToSource:
@@ -2163,7 +2163,7 @@

moveToward
Source:
@@ -2247,7 +2247,7 @@

overlapped<
Source:
@@ -2454,7 +2454,7 @@

overlappin
Source:
@@ -2667,7 +2667,7 @@

overlapsSource:
@@ -2857,7 +2857,7 @@

pushSource:
@@ -3032,7 +3032,7 @@

removeSource:
@@ -3192,7 +3192,7 @@

removeAllSource:
@@ -3277,7 +3277,7 @@

sizeSource:
@@ -3360,7 +3360,7 @@

toStringSource:
@@ -3471,7 +3471,3455 @@

updateSource:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + + + + + + + + + + + + + + + +
+ +
+ +

+ Group +

+ + +
+ +
+
+ + +
+ + + +

new Group()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +

Classes

+ +
+
Group
+
+
+ + + + + + + +

Members

+ + + +
+

amount :Number

+ + + + +
+ Depending on the value that the amount property is set to, the group will +either add or remove sprites. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

ani :SpriteAnimation

+ + + + +
+ Reference to the group's current animation. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+ + + + + + +
+ + + +
+

animation :SpriteAnimation

+ + + + +
+ Reference to the group's current animation. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+ + + + + + +
+ + + +
+

anis :SpriteAnimations

+ + + + +
+ The group's animations. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +SpriteAnimations + + +
  • +
+ + + + + +
+ + + +
+

image :p5.Image

+ + + + +
+ Reference to the group's current image. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Image + + +
  • +
+ + + + + +
+ + + +
+

img :p5.Image

+ + + + +
+ Reference to the group's current image. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Image + + +
  • +
+ + + + + +
+ + + + + +

Methods

+ + + +
+ + + +

applyForce()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

applyForceScaled()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

applyTorque()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

attractTo()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

collided(target, callbackopt) → {Boolean}

+ + + + + +
+ Returns true on the first frame that the group no longer overlaps +with the target sprite or group. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Boolean + + +
+
+ + + +
+ + + +
+ + +
+ + + +

collides(target, callbackopt)

+ + + + + +
+ Returns true on the first frame that the group collides with the +target sprite or group. + +Custom collision event handling can be done by using this function +in an if statement or adding a callback as the second parameter. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

colliding(target, callbackopt) → {Number}

+ + + + + +
+ Returns a truthy value while the group is colliding with the +target sprite or group. The value is the number of frames that +the group has been colliding with the target. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ frames +
+ + +
+ + + +
+ + +
+ + + +

cull(top|size, bottom|cb, leftopt, rightopt, cb(sprite)opt) → {Number}

+ + + + + +
+ Remove sprites that go outside the given culling boundary +relative to the camera. + +Sprites with chain colliders can not be culled. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
top|size + + +Number + + + + + + + + + + + The distance that sprites can move below the p5.js canvas before they are removed. *OR* The distance sprites can travel outside the screen on all sides before they get removed. + +
bottom|cb + + +Number + + + + + + + + + + + The distance that sprites can move below the p5.js canvas before they are removed. + +
left + + +Number + + + + + + <optional>
+ + + + + +
+ The distance that sprites can move beyond the left side of the p5.js canvas before they are removed. + +
right + + +Number + + + + + + <optional>
+ + + + + +
+ The distance that sprites can move beyond the right side of the p5.js canvas before they are removed. + +
cb(sprite) + + +function + + + + + + <optional>
+ + + + + +
+ The callback is given the sprite that +passed the cull boundary, if no callback is given the sprite is +removed by default + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ The number of sprites culled +
+ + +
+ + + +
+ + +
+ + + +

draw()

+ + + + + +
+ Draws all the sprites in the group. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

move()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

moveTo()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

moveTowards()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

overlapped(target, callbackopt) → {Boolean}

+ + + + + +
+ Returns true on the first frame that the group no longer overlaps +with the target sprite or group. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Boolean + + +
+
+ + + +
+ + + +
+ + +
+ + + +

overlapping(target, callbackopt) → {Number}

+ + + + + +
+ Returns a truthy value while the group is overlapping with the +target sprite or group. The value returned is the number of +frames the group has been overlapping with the target. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ frames +
+ + +
+ + + +
+ + +
+ + + +

overlaps(target, callbackopt)

+ + + + + +
+ Returns true on the first frame that the group overlaps with the +target sprite or group. + +Custom overlap event handling can be done by using this function +in an if statement or adding a callback as the second parameter. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

push(…sprites) → {Number}

+ + + + + +
+ Its better to use the group Sprite constructor instead. +`new group.Sprite()` which both creates a group sprite using +soft inheritance and adds it to the group. + +Adds a sprite or multiple sprites to the group, whether they were +already in the group or not, just like with the Array.push() +method. Only sprites can be added to a group. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
sprites + + +Sprite + + + + + + + + + + <repeatable>
+ +
+ The sprite or sprites to be added + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ the new length of the group +
+ + +
+ + + +
+ + +
+ + + +

remove(item) → {Sprite}

+ + + + + +
+ If no input is given all sprites in the group are removed. + +If a sprite or index is given, that sprite is removed from the +group, but not from the sketch or any other groups it may be in. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
item + + +Sprite + + + + + The sprite to be removed + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Sprite + + +
+
+ + +
+ the removed sprite +
+ + +
+ + + +
+ + +
+ + + +

removeAll()

+ + + + + +
+ Removes all sprites from the group and destroys the group. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

size()

+ + + + + +
+ Alias for group.length +
+ + + + + +
+ + + + + + + + + + + + + + + + +
Deprecated:
  • Yes
+ + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

toString() → {String}

+ + + + + +
+ Returns the group's unique identifier. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +String + + +
+
+ + +
+ groupID +
+ + +
+ + + +
+ + +
+ + + +

update()

+ + + + + +
+ Updates all the sprites in the group. See sprite.update for +more information. + +By default, allSprites.update is called after every draw call. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
@@ -3523,7 +6971,7 @@

update
- Generated by JSDoc 4.0.2 on Mon Sep 11 2023 17:20:52 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 20:35:56 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/GroupSprite.html b/docs/GroupSprite.html new file mode 100644 index 00000000..f14a75bd --- /dev/null +++ b/docs/GroupSprite.html @@ -0,0 +1,170 @@ + + + + + + GroupSprite - Documentation + + + + + + + + + + + + + + + + + +
+ +

GroupSprite

+ + + + + + + +
+ +
+ +

+ GroupSprite +

+ + +
+ +
+
+ + +
+ + + +

new GroupSprite()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +
+ +
+ Generated by JSDoc 4.0.2 on Tue Sep 12 2023 20:35:56 GMT-0500 (Colombia Standard Time) using the Minami theme. +
+ + + + + \ No newline at end of file diff --git a/docs/HingeJoint.html b/docs/HingeJoint.html index b6c8cb05..90fcc354 100644 --- a/docs/HingeJoint.html +++ b/docs/HingeJoint.html @@ -567,7 +567,7 @@
Type:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/InputDevice.html b/docs/InputDevice.html index dfcb643d..7ecf425e 100644 --- a/docs/InputDevice.html +++ b/docs/InputDevice.html @@ -1279,7 +1279,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/Joint.html b/docs/Joint.html index 8af9c9be..b61a2274 100644 --- a/docs/Joint.html +++ b/docs/Joint.html @@ -1200,7 +1200,7 @@

remove
- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/P5Play.html b/docs/P5Play.html index 2fd7a43c..2daaa12a 100644 --- a/docs/P5Play.html +++ b/docs/P5Play.html @@ -167,7 +167,7 @@

new P5Play
- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/RopeJoint.html b/docs/RopeJoint.html index 1f416f0f..4d9bb365 100644 --- a/docs/RopeJoint.html +++ b/docs/RopeJoint.html @@ -314,7 +314,7 @@

maxLength
- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/SliderJoint.html b/docs/SliderJoint.html index c0815aaf..f9fe94af 100644 --- a/docs/SliderJoint.html +++ b/docs/SliderJoint.html @@ -569,7 +569,7 @@
Type:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/Sprite.html b/docs/Sprite.html index 1514f41a..5ca2f84e 100644 --- a/docs/Sprite.html +++ b/docs/Sprite.html @@ -24,7 +24,7 @@
@@ -56,6 +56,10370 @@

+

new Sprite()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ + + + + + +

Classes

+ +
+
Sprite
+
+
+ + + + + + + +

Members

+ + + +
+

allowSleeping :Boolean

+ + + + +
+ This property disables the ability for a sprite to "sleep". + +"Sleeping" sprites are not included in the physics simulation, a +sprite starts "sleeping" when it stops moving and doesn't collide +with anything that it wasn't already touching. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • true
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

animation :SpriteAnimation

+ + + + +
+ Reference to the sprite's current animation. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+ + + + + + +
+ + + +
+

autoDraw :Boolean

+ + + + +
+ autoDraw is a property of all groups that controls whether +a group is automatically drawn to the screen after the end +of each draw cycle. + +It only needs to be set to false once and then it will +remain false for the rest of the sketch, unless changed. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • true
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

autoUpdate :Boolean

+ + + + +
+ autoUpdate is a property of all groups that controls whether +a group is automatically updated after the end of each draw +cycle. + +It only needs to be set to false once and then it will +remain false for the rest of the sketch, unless changed. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • true
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

bearing

+ + + + +
+ A bearing indicates the direction that needs to be followed to +reach a destination. Setting a sprite's bearing doesn't do +anything by itself. You can apply a force at the sprite's +bearing angle using the `applyForce` function. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
Example
+ +
sprite.bearing = angle;
+sprite.applyForce(amount);
+ + +
+ + + +
+

bounciness :Number

+ + + + +
+ The bounciness of the sprite's physics body. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0.2
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

centerOfMass :p5.Vector

+ + + + +
+ The center of mass of the sprite's physics body. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Vector + + +
  • +
+ + + + + +
+ + + +
+

collider :String

+ + + + +
+ The sprite's collider type. Default is 'dynamic'. + +The collider type can be one of the following strings: +'dynamic', 'static', 'kinematic', 'none'. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 'dynamic'
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +String + + +
  • +
+ + + + + +
+ + + +
+

color :p5.Color

+ + + + +
+ The sprite's current color. By default sprites get a random color. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • random color
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Color + + +
  • +
+ + + + + +
+ + + +
+

colour :p5.Color

+ + + + +
+ Alias for color. colour is the British English spelling. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • random color
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Color + + +
  • +
+ + + + + +
+ + + +
+

d :Number

+ + + + +
+ The diameter of a circular sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

density :Number

+ + + + +
+ The density of the sprite's physics body. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 5
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

diameter :Number

+ + + + +
+ The diameter of a circular sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

direction :Number

+ + + + +
+ The angle of the sprite's movement or it's rotation angle if the +sprite is not moving. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0 ("right")
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

drag :Number

+ + + + +
+ The amount of resistance a sprite has to being moved. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

draw

+ + + + +
+ Displays the sprite. + +This function is called automatically at +the end of each p5.js draw function call but it can also be run +separately to customize the order sprites are drawn in relation +to other stuff drawn to the p5.js canvas. Also see the sprite.layer +property. + +A sprite's draw function can be overridden with a +custom draw function, in which the center of the sprite is +at (0, 0). +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
Example
+ +
sprite.draw = function() {
+  // an oval
+  ellipse(0,0,20,10);
+}
+ + +
+ + + +
+

dynamic :Boolean

+ + + + +
+ True if the sprite's physics body is dynamic. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • true
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

fill :p5.Color

+ + + + +
+ Alias for sprite.fillColor +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • random color
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Color + + +
  • +
+ + + + + +
+ + + +
+

fillColor :p5.Color

+ + + + +
+ Alias for sprite.color +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • random color
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Color + + +
  • +
+ + + + + +
+ + + +
+

fixture

+ + + + +
+ Returns the first node in a linked list of the planck physics +body's fixtures. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
+ + + +
+

fixtureList

+ + + + +
+ Returns the first node in a linked list of the planck physics +body's fixtures. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
+ + + +
+

friction :Number

+ + + + +
+ The amount the sprite's physics body resists moving +when rubbing against another physics body. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0.5
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

h :Number

+ + + + +
+ The height of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

halfHeight :Number

+ + + + +
+ Half the height of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

halfWidth :Number

+ + + + +
+ Half the width of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

heading :String

+ + + + +
+ The sprite's heading. This is a string that can be set to +"up", "down", "left", "right", "upRight", "upLeft", "downRight" + +It ignores cardinal direction word order, capitalization, spaces, +underscores, and dashes. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • undefined
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +String + + +
  • +
+ + + + + +
+ + + +
+

height :Number

+ + + + +
+ The height of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

hh :Number

+ + + + +
+ Half the height of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

hw :Number

+ + + + +
+ Half the width of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

image :p5.Image

+ + + + +
+ A reference to the sprite's current image. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Image + + +
  • +
+ + + + + +
+ + + +
+

img :p5.Image

+ + + + +
+ A reference to the sprite's current image. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Image + + +
  • +
+ + + + + +
+ + + +
+

isMoving :Boolean

+ + + + +
+ Read only. True if the sprite is moving. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

isSuperFast :Boolean

+ + + + +
+ Set this to true if the sprite goes really fast to prevent +inaccurate physics simulation. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • false
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

kinematic :Boolean

+ + + + +
+ True if the sprite's physics body is kinematic. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • false
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

layer :Number

+ + + + +
+ By default sprites are drawn in the order they were created in. +You can change the draw order by editing sprite's layer +property. Sprites with the highest layer value get drawn first. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

life :Number

+ + + + +
+ The number of frame cycles before the sprite is removed. + +Set it to initiate a countdown, every draw cycle the value is +reduced by 1 unit. If it becomes less than or equal to 0, the +sprite will be removed. + +It must be set to a positive integer lower than the max value of +a 32 bit signed integer, 2147483647, which is the default value +representing infinite life. This limitation makes sprite netcode +smaller. But don't worry, at 60 fps this gives users a definable +sprite life range between 1 frame and ~411 days! +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 2147483647
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

mass :Number

+ + + + +
+ The mass of the sprite's physics body. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

mirror :Object

+ + + + +
+ The sprite's mirror states. +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Boolean + + + + The sprite's horizontal mirror state.
y + + +Boolean + + + + The sprite's vertical mirror state.
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • {x: false, y: false}
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
+ + + +
+

offset :object

+ + + + +
+ Offsetting the sprite moves the sprite's physics body relative +to its center. + +The sprite's x and y properties represent its center in world +coordinates. This point is also the sprite's center of rotation. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +object + + +
  • +
+ + + + + +
+ + + +
+

pixelPerfect :Boolean

+ + + + +
+ By default p5play draws sprites with subpixel rendering. + +Set pixelPerfect to true to make p5play always display sprites +at integer pixel precision. This is useful for making retro games. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • false
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

pos :p5.Vector

+ + + + +
+ The position vector {x, y} +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Vector + + +
  • +
+ + + + + +
+ + + +
+

position :p5.Vector

+ + + + +
+ The position vector {x, y} +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Vector + + +
  • +
+ + + + + +
+ + + +
+

previousPosition :Object

+ + + + +
+ Verbose alias for sprite.prevPos +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
+ + + +
+

previousRotation :Number

+ + + + +
+ Verbose alias for sprite.prevRotation +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

r :Number

+ + + + +
+ The radius of a circular sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

radius :Number

+ + + + +
+ The radius of a circular sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

removed :Boolean

+ + + + +
+ If the sprite has been removed from the world. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • false
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

rotation :Number

+ + + + +
+ The angle of the sprite's rotation, not the direction it is moving. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

rotationDrag :Number

+ + + + +
+ The amount the sprite resists rotating. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

rotationLock :Boolean

+ + + + +
+ If true, the sprite can not rotate. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • false
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

rotationSpeed :Number

+ + + + +
+ The speed of the sprite's rotation. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

scale :Number|Object

+ + + + +
+ Scale of the sprite's physics body. Default is {x: 1, y: 1} + +The getter for sprite.scale returns the scale as an object with +x and y properties. + +The valueOf function for sprite.scale returns the scale as a +number. This enables users to do things like `sprite.scale *= 2` +to double the sprite's scale. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 1
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number +| + +Object + + +
  • +
+ + + + + +
+ + + +
+

shape :String

+ + + + +
+ The kind of shape: 'box', 'circle', 'chain', or 'polygon'. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • box
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +String + + +
  • +
+ + + + + +
+ + + +
+

sleeping :Boolean

+ + + + +
+ Wake a sprite up or put it to sleep. + +"Sleeping" sprites are not included in the physics simulation, a +sprite starts "sleeping" when it stops moving and doesn't collide +with anything that it wasn't already touching. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • true
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

speed :Number

+ + + + +
+ The sprite's speed. + +Setting speed to a negative value will make the sprite move +180 degrees opposite of its current direction angle. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 0
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

static :Boolean

+ + + + +
+ Is the sprite's physics collider static? +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • false
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

stroke :p5.Color

+ + + + +
+ Alias for sprite.strokeColor +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Color + + +
  • +
+ + + + + +
+ + + +
+

strokeColor :p5.Color

+ + + + +
+ The sprite's stroke color. By default the stroke of a sprite +is determined by its collider type. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Color + + +
  • +
+ + + + + +
+ + + +
+

strokeWeight :Number

+ + + + +
+ The sprite's stroke weight, the thickness of its outline. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • undefined
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

textColor :p5.Color

+ + + + +
+ The sprite's current text color. Black by default. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • black (#000000)
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +p5.Color + + +
  • +
+ + + + + +
+ + + +
+

update

+ + + + +
+ You can set the sprite's update function to a custom +update function which by default, will be run after every p5.js +draw call. + +This function updates the sprite's animation, mouse, and + +There's no way to individually update a sprite or group +of sprites in the physics simulation though. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
+ + + +
+

vertices :Array:.<p5.Vector:>

+ + + + +
+ Read only. The sprite's vertices. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Array:.<p5.Vector:> + + +
  • +
+ + + + + +
+ + + +
+

visible :Boolean

+ + + + +
+ If true the sprite is shown, if set to false the sprite is hidden. + +Becomes null when the sprite is off screen but will be drawn and +set to true again if it goes back on screen. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • true
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

w :Number

+ + + + +
+ The width of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

width :Number

+ + + + +
+ The width of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

x :Number

+ + + + +
+ The horizontal position of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

y :Number

+ + + + +
+ The vertical position of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + + + +

Methods

+ + + +
+ + + +

addCollider(offsetX, offsetY, w, h)

+ + + + + +
+ Adds a collider (fixture) to the sprite's physics body. + +It accepts parameters in a similar format to the Sprite +constructor except the first two parameters are x and y offsets, +the distance new collider should be from the center of the sprite. + +This function also auto-resets the sprite's mass, recalculating +the sprite's mass based on its new size. + +One limitation of the current implementation is that sprites +with multiple colliders can't have their collider +type changed without losing every collider added to the +sprite besides the first. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offsetX + + +Number + + + + + distance from the center of the sprite + +
offsetY + + +Number + + + + + distance from the center of the sprite + +
w + + +Number + + + + + width of the collider + +
h + + +Number + + + + + height of the collider + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

addDefaultSensors()

+ + + + + +
+ This function is used automatically if a sprite overlap detection +function is called but the sprite has no overlap sensors. + +It creates sensor fixtures that are the same size as the sprite's +colliders. If you'd like to add more sensors to a sprite, use the +addSensor function. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

addSensor(offsetX, offsetY, w, h)

+ + + + + +
+ Adds a sensor to the sprite's physics body that's used to detect +overlaps with other sprites. + +It accepts parameters in a similar format to the Sprite +constructor except the first two parameters are x and y offsets, +the relative distance the new sensor should be from the center of +the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offsetX + + +Number + + + + + distance from the center of the sprite + +
offsetY + + +Number + + + + + distance from the center of the sprite + +
w + + +Number + + + + + width of the collider + +
h + + +Number + + + + + height of the collider + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

angleTo(x, y) → {Number}

+ + + + + +
+ Finds the angle from this sprite to the given position or object +with x and y properties. + +Can be used to change the direction of a sprite so it moves +to a position or object. + +Used internally by `moveTo` and `moveTowards`. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + + + +
y + + +Number + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ angle +
+ + +
+ + + +
+
Example
+ +
spriteA.direction = spriteA.angleTo(spriteB);
+ +
+ +
+ + +
+ + + +

angleToFace(x, y, facing) → {Number}

+ + + + + +
+ Finds the minimium amount the sprite would have to rotate to +"face" a position at a specified "facing" rotation. + +Used internally by `rotateTo` and `rotateTowards`. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + + + +
y + + +Number + + + + + + +
facing + + +Number + + + + + rotation angle the sprite should be at when "facing" the position, default is 0 + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ minimum angle of rotation to face the position +
+ + +
+ + + +
+ + +
+ + + +

applyForce(amount, originopt)

+ + + + + +
+ If this function is given a force amount, the force is applied +at the angle of the sprite's current bearing. Force can +also be given as a vector. + +The origin of the force can be given as a vector or as x and y +coordinates. If no origin is given, the force is applied to the +center of the sprite. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
amount + + +Number + + + + + + + + + + + + +
origin + + +Vector + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + + + +
+
Example
+ +
sprite.applyForce(amount);
+sprite.applyForce(amount, {x: originX, y: originY});
+sprite.applyForce(x, y);
+sprite.applyForce(x, y, {x: originX, y: originY});
+sprite.applyForce({x, y}, {x: originX, y: originY});
+ +
+ +
+ + +
+ + + +

applyForceScaled(amount, originopt)

+ + + + + +
+ Applies a force that's scaled to the sprite's mass. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
amount + + +Number + + + + + + + + + + + + +
origin + + +Vector + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

applyTorque(torque)

+ + + + + +
+ Apply a torque on the sprite's physics body. +Torque is the force that causes rotation. +A positive torque will rotate the sprite clockwise. +A negative torque will rotate the sprite counter-clockwise. + +This function is the rotational equivalent of applyForce(). +It will not imperatively set the sprite's rotation. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
torque + + +Number + + + + + The amount of torque to apply. + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

attractTo(x, y, force, radiusopt, easingopt)

+ + + + + +
+ Applies a force to the sprite's center of mass attracting it to +the given position. + +Radius and easing not implemented yet! +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
x + + +Number + + + + + + + + + + + + +
y + + +Number + + + + + + + + + + + + +
force + + +Number + + + + + + + + + + + + +
radius + + +Number + + + + + + <optional>
+ + + + + +
+ infinite if not given + +
easing + + +Number + + + + + + <optional>
+ + + + + +
+ solid if not given + +
+ + + + + + + + + + + + + + + + +
+
Example
+ +
sprite.attractTo(x, y, force);
+sprite.attractTo({x, y}, force);
+ +
+ +
+ + +
+ + + +

(async) changeAni(…anis)

+ + + + + +
+ Changes the sprite's animation. Use `addAni` to define the +animation(s) first. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
anis + + +String + + + + + + + + + + <repeatable>
+ +
+ the names of one or many animations to be played in +sequence + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + + +
+ A promise that fulfills when the animation or sequence of animations +completes +
+ + +
+ + + +
+ + +
+ + + +

changeAnimation(…anis)

+ + + + + +
+ Changes the sprite's animation. Use `addAni` to define the +animation(s) first. Alt for `changeAni`. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
anis + + +String + + + + + + + + + + <repeatable>
+ +
+ the names of one or many animations to be played in +sequence + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + + +
+ A promise that fulfills when the animation or sequence of animations +completes +
+ + +
+ + + +
+ + +
+ + + +

collided(target, callbackopt) → {Boolean}

+ + + + + +
+ Returns true on the first frame that the sprite no longer overlaps +with the target sprite or group. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Boolean + + +
+
+ + + +
+ + + +
+ + +
+ + + +

collides(target, callbackopt)

+ + + + + +
+ Returns true on the first frame that the sprite collides with the +target sprite or group. + +Custom collision event handling can be done by using this function +in an if statement or adding a callback as the second parameter. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

colliding(target, callbackopt) → {Number}

+ + + + + +
+ Returns a truthy value while the sprite is colliding with the +target sprite or group. The value is the number of frames that +the sprite has been colliding with the target. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ frames +
+ + +
+ + + +
+ + +
+ + + +

move(distance, direction, speed) → {Promise}

+ + + + + +
+ Move the sprite a certain distance from its current position. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + + [optional] + +
direction + + +Number +| + +String + + + + + [optional] + +
speed + + +Number + + + + + [optional] + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Promise + + +
+
+ + +
+ resolves when the movement is complete or cancelled +
+ + +
+ + + +
+
Example
+ +
sprite.move(distance);
+sprite.move(distance, direction);
+sprite.move(distance, direction, speed);
+
+sprite.move(directionName);
+sprite.move(directionName, speed);
+ +
+ +
+ + +
+ + + +

moveTo(x|position, y, speed) → {Promise}

+ + + + + +
+ Move the sprite to a position. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x|position + + +Number +| + +Object + + + + + destination x or any object with x and y properties + +
y + + +Number + + + + + destination y + +
speed + + +Number + + + + + [optional] + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Promise + + +
+
+ + +
+ resolves to true when the movement is complete +or to false if the sprite will not reach its destination +
+ + +
+ + + +
+ + +
+ + + +

moveTowards(x|position, y, tracking)

+ + + + + +
+ Moves a sprite towards a position. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x|position + + +Number +| + +Object + + + + + destination x or any object with x and y properties + +
y + + +Number + + + + + destination y + +
tracking + + +Number + + + + + [optional] 1 represents 1:1 tracking, the mouse moves to the destination immediately, 0 represents no tracking. Default is 0.1 (10% tracking). + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

overlapped(target, callbackopt) → {Boolean}

+ + + + + +
+ Returns true on the first frame that the sprite no longer overlaps +with the target sprite or group. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Boolean + + +
+
+ + + +
+ + + +
+ + +
+ + + +

overlapping(target, callbackopt) → {Number}

+ + + + + +
+ Returns a truthy value while the sprite is overlapping with the +target sprite or group. The value returned is the number of +frames the sprite has been overlapping with the target. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Number + + +
+
+ + +
+ frames +
+ + +
+ + + +
+ + +
+ + + +

overlaps(target, callbackopt)

+ + + + + +
+ Returns true on the first frame that the sprite overlaps with the +target sprite or group. + +Custom overlap event handling can be done by using this function +in an if statement or adding a callback as the second parameter. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
target + + +Sprite +| + +Group + + + + + + + + + + + + +
callback + + +function + + + + + + <optional>
+ + + + + +
+ + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

remove()

+ + + + + +
+ Removes the Sprite from the sketch and all the groups it +belongs to. + +When a sprite is removed it will not be drawn or updated anymore. +If it has a physics body, it will be removed from the +physics world simulation. + +There's no way to undo this operation. If you want to hide a +sprite use `sprite.visible = false` instead. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

removeColliders()

+ + + + + +
+ Removes the physics body colliders from the sprite but not +overlap sensors. + +Only use this method if you never want to use the sprite's +colliders again. If you want to disable colliders without +removing them, use the overlaps, overlapping, or overlapped +functions instead. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

removeSensors()

+ + + + + +
+ Removes overlap sensors from the sprite. + +Only use this method if you never want to use the sprite's +overlap sensors again. To disable overlap sensors without +removing them, use the collides, colliding, or collided functions +instead. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

resetMass()

+ + + + + +
+ Recalculates the sprite's mass based on its current +density and size. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

rotate(angle, speed) → {Promise}

+ + + + + +
+ Rotates the sprite by an amount at a specified angles per frame speed. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
angle + + +Number + + + + + the amount to rotate the sprite + +
speed + + +Number + + + + + the amount of rotation per frame, default is 1 + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Promise + + +
+
+ + +
+ a promise that resolves when the rotation is complete +
+ + +
+ + + +
+ + +
+ + + +

rotateTo(angle|position, speed, facing) → {Promise}

+ + + + + +
+ Rotates the sprite to an angle or to face a position. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
angle|position + + +Number +| + +Object + + + + + + +
speed + + +Number + + + + + the amount of rotation per frame, default is 1 + +
facing + + +Number + + + + + (only if position is given) the rotation angle the sprite should be at when "facing" the position, default is 0 + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Promise + + +
+
+ + +
+ a promise that resolves when the rotation is complete +
+ + +
+ + + +
+ + +
+ + + +

rotateTowards(angle|position, tracking, facing)

+ + + + + +
+ Rotates the sprite towards an angle or position +with x and y properties. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
angle|position + + +Number +| + +Object + + + + + angle in degrees or an object with x and y properties + +
tracking + + +Number + + + + + percent of the distance to rotate on each frame towards the target angle, default is 0.1 (10%) + +
facing + + +Number + + + + + (only if position is given) rotation angle the sprite should be at when "facing" the position, default is 0 + +
+ + + + + + + + + + + + + + + + +
+ + +
+ + + +

toString()

+ + + + + +
+ Warning: This function might be changed in a future release. + +Returns the sprite's unique identifier `sprite.idNum`. +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+
Returns:
+ + + + +
+ the sprite's id +
+ + +
+ + + +
+ + + + + + +
+ +
+ + + + + + + +
+ +
+ +

+ #Sprite + + Sprite +

+ + +
+ +
+
+ + +
+ + +

new Sprite(xopt, yopt, wopt, hopt, collideropt) → {Sprite}

@@ -106,7 +10470,7 @@

new SpriteSource:
@@ -467,7 +10831,7 @@

allowSle
Source:
@@ -541,7 +10905,7 @@

animationSource:
@@ -625,7 +10989,7 @@

autoDrawSource:
@@ -709,7 +11073,7 @@

autoUpdate<
Source:
@@ -786,7 +11150,7 @@

bearingSource:
@@ -861,7 +11225,7 @@

bounciness<
Source:
@@ -935,7 +11299,7 @@

centerOfM
Source:
@@ -1017,7 +11381,7 @@

colliderSource:
@@ -1096,7 +11460,7 @@

colorSource:
@@ -1175,7 +11539,7 @@

colourSource:
@@ -1249,7 +11613,7 @@

dSource:
@@ -1328,7 +11692,7 @@

densitySource:
@@ -1402,7 +11766,7 @@

diameterSource:
@@ -1482,7 +11846,7 @@

directionSource:
@@ -1561,7 +11925,7 @@

dragSource:
@@ -1645,7 +12009,7 @@

drawSource:
@@ -1722,7 +12086,7 @@

dynamicSource:
@@ -1801,7 +12165,7 @@

fillSource:
@@ -1880,7 +12244,7 @@

fillColorSource:
@@ -1955,7 +12319,7 @@

fixtureSource:
@@ -2020,7 +12384,7 @@

fixtureLis
Source:
@@ -2090,7 +12454,7 @@

frictionSource:
@@ -2164,7 +12528,7 @@

hSource:
@@ -2238,7 +12602,7 @@

halfHeight<
Source:
@@ -2312,7 +12676,7 @@

halfWidthSource:
@@ -2395,7 +12759,7 @@

headingSource:
@@ -2469,7 +12833,7 @@

heightSource:
@@ -2543,7 +12907,7 @@

hhSource:
@@ -2617,7 +12981,7 @@

hwSource:
@@ -2691,7 +13055,7 @@

imageSource:
@@ -2765,7 +13129,7 @@

imgSource:
@@ -2839,7 +13203,7 @@

isMovingSource:
@@ -2919,7 +13283,7 @@

isSuperFas
Source:
@@ -2998,7 +13362,7 @@

kinematicSource:
@@ -3074,7 +13438,7 @@

layerSource:
@@ -3163,7 +13527,7 @@

lifeSource:
@@ -3237,7 +13601,7 @@

massSource:
@@ -3395,7 +13759,7 @@
Properties:
Source:
@@ -3473,7 +13837,7 @@

offsetSource:
@@ -3555,7 +13919,7 @@

pixelPerf
Source:
@@ -3629,7 +13993,7 @@

posSource:
@@ -3703,7 +14067,7 @@

positionSource:
@@ -3777,7 +14141,7 @@

previ
Source:
@@ -3851,7 +14215,7 @@

previ
Source:
@@ -3925,7 +14289,7 @@

rSource:
@@ -3999,7 +14363,7 @@

radiusSource:
@@ -4078,7 +14442,7 @@

removedSource:
@@ -4157,7 +14521,7 @@

rotationSource:
@@ -4236,7 +14600,7 @@

rotationD
Source:
@@ -4315,7 +14679,7 @@

rotationL
Source:
@@ -4394,7 +14758,7 @@

rotation
Source:
@@ -4480,7 +14844,7 @@

scaleSource:
@@ -4562,7 +14926,7 @@

shapeSource:
@@ -4645,7 +15009,7 @@

sleepingSource:
@@ -4727,7 +15091,7 @@

speedSource:
@@ -4806,7 +15170,7 @@

staticSource:
@@ -4880,7 +15244,7 @@

strokeSource:
@@ -4955,7 +15319,7 @@

strokeColo
Source:
@@ -5034,7 +15398,7 @@

strokeWei
Source:
@@ -5113,7 +15477,7 @@

textColorSource:
@@ -5194,7 +15558,7 @@

updateSource:
@@ -5258,7 +15622,7 @@

verticesSource:
@@ -5340,7 +15704,7 @@

visibleSource:
@@ -5414,7 +15778,7 @@

wSource:
@@ -5488,7 +15852,7 @@

widthSource:
@@ -5562,7 +15926,7 @@

xSource:
@@ -5636,7 +16000,7 @@

ySource:
@@ -5732,7 +16096,7 @@

addCollide
Source:
@@ -5950,7 +16314,7 @@

addD
Source:
@@ -6039,7 +16403,7 @@

addSensorSource:
@@ -6258,7 +16622,7 @@

angleToSource:
@@ -6454,7 +16818,7 @@

angleToFac
Source:
@@ -6672,7 +17036,7 @@

applyForce<
Source:
@@ -6864,7 +17228,7 @@

apply
Source:
@@ -7051,7 +17415,7 @@

applyTorqu
Source:
@@ -7189,7 +17553,7 @@

attractToSource:
@@ -7483,7 +17847,7 @@

(async) chan
Source:
@@ -7646,7 +18010,7 @@

change
Source:
@@ -7809,7 +18173,7 @@

collidedSource:
@@ -8018,7 +18382,7 @@

collidesSource:
@@ -8204,7 +18568,7 @@

collidingSource:
@@ -8413,7 +18777,7 @@

moveSource:
@@ -8640,7 +19004,7 @@

moveToSource:
@@ -8856,7 +19220,7 @@

moveToward
Source:
@@ -9047,7 +19411,7 @@

overlapped<
Source:
@@ -9254,7 +19618,7 @@

overlappin
Source:
@@ -9467,7 +19831,7 @@

overlapsSource:
@@ -9659,7 +20023,7 @@

removeSource:
@@ -9748,7 +20112,7 @@

remove
Source:
@@ -9836,7 +20200,7 @@

removeSe
Source:
@@ -9920,7 +20284,7 @@

resetMassSource:
@@ -10003,7 +20367,7 @@

rotateSource:
@@ -10189,7 +20553,7 @@

rotateToSource:
@@ -10405,7 +20769,7 @@

rotateTo
Source:
@@ -10597,7 +20961,7 @@

toStringSource:
@@ -10662,7 +21026,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Mon Sep 11 2023 17:20:52 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 20:35:56 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/SpriteAnimation.html b/docs/SpriteAnimation.html index 89f133dc..a2a7d5cc 100644 --- a/docs/SpriteAnimation.html +++ b/docs/SpriteAnimation.html @@ -2275,7 +2275,7 @@

stop
- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/Subgroup.html b/docs/Subgroup.html new file mode 100644 index 00000000..edb47296 --- /dev/null +++ b/docs/Subgroup.html @@ -0,0 +1,170 @@ + + + + + + Subgroup - Documentation + + + + + + + + + + + + + + + + + +
+ +

Subgroup

+ + + + + + + +
+ +
+ +

+ Subgroup +

+ + +
+ +
+
+ + +
+ + + +

new Subgroup()

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +
+ +
+ Generated by JSDoc 4.0.2 on Tue Sep 12 2023 20:35:56 GMT-0500 (Colombia Standard Time) using the Minami theme. +
+ + + + + \ No newline at end of file diff --git a/docs/Tiles.html b/docs/Tiles.html index 35a97360..723e62d8 100644 --- a/docs/Tiles.html +++ b/docs/Tiles.html @@ -326,7 +326,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/WheelJoint.html b/docs/WheelJoint.html index 460b57b9..f56aad2c 100644 --- a/docs/WheelJoint.html +++ b/docs/WheelJoint.html @@ -331,7 +331,7 @@
Type:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/World.html b/docs/World.html index f40bb48c..f90386f8 100644 --- a/docs/World.html +++ b/docs/World.html @@ -1382,7 +1382,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/global.html b/docs/global.html index e1327f9e..053f4810 100644 --- a/docs/global.html +++ b/docs/global.html @@ -10664,7 +10664,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/index.html b/docs/index.html index 0a195b06..d12787f4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -57,7 +57,7 @@
- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:38 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/docs/p5play.js.html b/docs/p5play.js.html index f2bfe97d..a2b02cfe 100644 --- a/docs/p5play.js.html +++ b/docs/p5play.js.html @@ -4728,7 +4728,7 @@

p5play.js

let _this = this; /** - * @type {Sprite.constructor} + * @type {Sprite} */ this.Sprite; @@ -4738,12 +4738,12 @@

p5play.js

} }; /** - * @type {Sprite.constructor} + * @type {Sprite} */ this.GroupSprite = this.Sprite; /** - * @type {Group.constructor} + * @type {Group} */ this.Group; @@ -4753,7 +4753,7 @@

p5play.js

} }; /** - * @type {Group.constructor} + * @type {Group} */ this.Subgroup = this.Group; @@ -8540,14 +8540,12 @@

p5play.js

this.leftStick = { x: 0, - y: 0, - btn: 0 + y: 0 }; this.rightStick = { x: 0, - y: 0, - btn: 0 + y: 0 }; this._btns = { @@ -9121,7 +9119,7 @@

p5play.js


- Generated by JSDoc 4.0.2 on Tue Sep 12 2023 19:06:37 GMT-0500 (Colombia Standard Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Tue Sep 12 2023 21:07:17 GMT-0500 (Colombia Standard Time) using the Minami theme.
diff --git a/package.json b/package.json index 83919cfa..87d234e0 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,9 @@ "main": "app/app.js", "scripts": { "tests": "jest tests", + "dist": "cp v3/p5play.js ../../pkg/p5play/p5play.js && cp v3/p5play.min.js ../../pkg/p5play/p5play.min.js", "docs": "jsdoc --configure docs/config/jsdoc.json", - "min": "minify v3/p5play.js > v3/p5play.min.js && cp v3/p5play.min.js ../../pkg/p5play/p5play.min.js", + "min": "minify v3/p5play.js > v3/p5play.min.js", "v": "npm version patch --force", "V": "npm version minor --force", "version": "git add -A", @@ -74,5 +75,5 @@ "make": "electron-forge make", "publish": "electron-forge publish" }, - "version": "1.6.3" + "version": "1.6.4" } diff --git a/v3/p5play.d.ts b/v3/p5play.d.ts index 1c23f506..15db4291 100644 --- a/v3/p5play.d.ts +++ b/v3/p5play.d.ts @@ -2510,12 +2510,10 @@ class _Contro extends InputDevice { leftStick: { x: number; y: number; - btn: number; }; rightStick: { x: number; y: number; - btn: number; }; gamepad: any; id: any; @@ -2524,12 +2522,10 @@ class _Contro extends InputDevice { get ls(): { x: number; y: number; - btn: number; }; get rs(): { x: number; y: number; - btn: number; }; get lb(): any; get rb(): any; diff --git a/v3/p5play.js b/v3/p5play.js index 57ac8bb1..6e35db38 100644 --- a/v3/p5play.js +++ b/v3/p5play.js @@ -4687,7 +4687,7 @@ p5.prototype.registerMethod('init', function p5playInit() { let _this = this; /** - * @type {Sprite.constructor} + * @type {Sprite} */ this.Sprite; @@ -4697,12 +4697,12 @@ p5.prototype.registerMethod('init', function p5playInit() { } }; /** - * @type {Sprite.constructor} + * @type {Sprite} */ this.GroupSprite = this.Sprite; /** - * @type {Group.constructor} + * @type {Group} */ this.Group; @@ -4712,7 +4712,7 @@ p5.prototype.registerMethod('init', function p5playInit() { } }; /** - * @type {Group.constructor} + * @type {Group} */ this.Subgroup = this.Group; @@ -8499,14 +8499,12 @@ main { this.leftStick = { x: 0, - y: 0, - btn: 0 + y: 0 }; this.rightStick = { x: 0, - y: 0, - btn: 0 + y: 0 }; this._btns = { diff --git a/v3/p5play.min.js b/v3/p5play.min.js index d0211980..922358ce 100644 --- a/v3/p5play.min.js +++ b/v3/p5play.min.js @@ -4,4 +4,4 @@ * @author quinton-ashley * @license gpl-v3-only */ -p5.prototype.registerMethod("init",(function(){if(void 0===window.planck)throw"planck.js must be loaded before p5play";const t=this,e=planck,i=60;if(void 0===window._p5play_gtagged&&"undefined"==typeof process){let t=document.createElement("script");t.src="https://www.googletagmanager.com/gtag/js?id=G-EHXNCTSYLK",t.async=!0,document.head.append(t),window._p5play_gtagged=!0,t.onload=()=>{window.dataLayer??=[],window.gtag=function(){dataLayer.push(arguments)},gtag("js",new Date),gtag("config","G-EHXNCTSYLK"),gtag("event","p5play_v3_12")}}this.angleMode("degrees");const s=(t,s,r)=>new e.Vec2(t*r/i,s*r/i),r=(t,s,r)=>new e.Vec2(t/r*i,s/r*i),o=t=>Math.abs(t)<=e.Settings.linearSlop,h=t=>Math.abs(t-Math.round(t))<=e.Settings.linearSlop?Math.round(t):t,n={_collisions:["_collides","_colliding","_collided"],_overlappers:["_overlaps","_overlapping","_overlapped"]};this.p5play=new class{constructor(){this.os={},this.context="web",this.standardizeKeyboard=!1,this.sprites={},this.groups={},this.groupsCreated=0,this.spritesCreated=0,this.spritesDrawn=0,this._renderStats={},this.disableImages=!1,this.palettes=[]}},delete this.P5Play;const a=console.log;this.log=console.log,this.Sprite=class{constructor(s,r,o,n,a){this.p=t,this.idNum,this.watch,this.mod=[];let u,c,_=[...arguments];if(void 0!==_[0]&&_[0]instanceof this.p.Group&&(u=_[0],_=_.slice(1)),_.length||(this._noArgs=!0),void 0!==_[0]&&isNaN(_[0])&&("string"==typeof _[0]||_[0]instanceof this.p.SpriteAnimation||_[0]instanceof p5.Image)&&(c=_[0],_=_.slice(1)),1==_.length&&"number"==typeof _[0])throw new v("Sprite",0,[_[0]]);if(s=_[0],r=_[1],o=_[2],n=_[3],a=_[4],this._originMode="center",Array.isArray(s)&&(s=void 0,r=void 0,o=_[0],n=_[1],a=_[2]),Array.isArray(o)||"string"==typeof n){if(isNaN(o)||(o=Number(o)),"number"!=typeof o&&Array.isArray(o[0])&&(this._originMode="start"),void 0!==n){if(Array.isArray(n))throw new v("Sprite",1,[`[[${o}], [${n}]]`]);!function(t){let e=t.slice(0,2);return"d"==t||"s"==t||"k"==t||"n"==t||"dy"==e||"st"==e||"ki"==e||"no"==e}(n)?o=d(o,n):a=n,n=void 0}}else isNaN(o)&&(a=o,o=void 0);this.idNum=this.p.p5play.spritesCreated,this._uid=1e3+this.idNum,this.p.p5play.sprites[this._uid]=this,this.p.p5play.spritesCreated++,this.groups=[],this.animations=new this.p.SpriteAnimations,this.joints=[],this.joints.removeAll=()=>{for(let t of this.joints)t.remove()},this._removed=!1,this._life=2147483647,this._visible=!0,this._pixelPerfect=!1,this._aniChangeCount=0,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={},u??=this.p.allSprites,u.dynamic&&(a??="dynamic"),u.kinematic&&(a??="kinematic"),u.static&&(a??="static"),a??=u.collider,this._shape=u.shape,this.tileSize=u.tileSize||1;let f=this;if(this._position={x:0,y:0},this._pos=t.createVector.call(t),Object.defineProperty(this._pos,"x",{get(){if(!f.body)return f._position.x;let t=f.body.getPosition().x/f.tileSize*i;return h(t)},set(t){if(f.body){let s=new e.Vec2(t*f.tileSize/i,f.body.getPosition().y);f.body.setPosition(s)}f._position.x=t}}),Object.defineProperty(this._pos,"y",{get(){if(!f.body)return f._position.y;let t=f.body.getPosition().y/f.tileSize*i;return h(t)},set(t){if(f.body){let s=new e.Vec2(f.body.getPosition().x,t*f.tileSize/i);f.body.setPosition(s)}f._position.y=t}}),this._velocity={x:0,y:0},this._vel=t.createVector.call(t),Object.defineProperties(this._vel,{x:{get(){let t;return t=f.body?f.body.getLinearVelocity().x:f._velocity.x,h(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new e.Vec2(t,f.body.getLinearVelocity().y)):f._velocity.x=t}},y:{get(){let t;return t=f.body?f.body.getLinearVelocity().y:f._velocity.y,h(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new e.Vec2(f.body.getLinearVelocity().x,t)):f._velocity.y=t}}}),this._mirror={_x:1,_y:1,get x(){return this._x<0},set x(t){f.watch&&(f.mod[22]=!0),this._x=t?-1:1},get y(){return this._y<0},set y(t){f.watch&&(f.mod[22]=!0),this._y=t?-1:1}},this._heading="right",this._layer=u._layer,this._layer??=this.p.allSprites._getTopLayer()+1,a??=u.collider,a&&"string"==typeof a||(a="dynamic"),this.collider=a,s??=u.x,void 0===s&&(s=this.p.width/this.p.allSprites.tileSize/2,this._vertexMode=!0),r??=u.y,void 0===r&&(r=this.p.height/this.p.allSprites.tileSize/2),null==o&&(o=u.w||u.width||u.d||u.diameter,n??=u.h||u.height),"function"==typeof s&&(s=s(u.length)),"function"==typeof r&&(r=r(u.length)),"function"==typeof o&&(o=o(u.length)),"function"==typeof n&&(n=n(u.length)),this.x=s,this.y=r,!u._isAllSpritesGroup&&!c)for(let t in u.animations){c=t;break}for(let t=u;t;t=this.p.p5play.groups[t.parent])this.groups.push(t);if(this.groups.reverse(),c){c instanceof p5.Image?this.addAni(c):("string"==typeof c?this._changeAni(c):this._ani=c.clone(),this._ani.name=c.name);let t=this.tileSize;o||1==this._ani.w&&1==this._ani.h||(o=this._ani.w/t,n||"circle"==this.shape||(n=this._ani.h/t))}if(this.groups=[],this.mouse=new this.p._SpriteMouse,"none"!=this.collider)this._vertexMode?this.addCollider(o,n):this.addCollider(0,0,o,n);else{if(this.w=o||(this.tileSize>1?1:50),this.h=n||this.w,Array.isArray(o))throw new Error('Cannot set the collider type of a sprite with a polygon or chain shape to "none". Try having the sprite overlap with other sprites instead.');this._shape=void 0!==o&&void 0===n?"circle":"box"}u._isAllSpritesGroup||this.p.allSprites.push(this),u.push(this),this._scale=new l,Object.defineProperty(this._scale,"x",{get(){return this._x},set(t){if(t==this._x)return;f.watch&&(f.mod[28]=!0);let e=t/this._x;f._w*=e,f._hw*=e,f._resizeColliders({x:e,y:1}),this._x=t,this._avg=.5*(this._x+this._y)}}),Object.defineProperty(this._scale,"y",{get(){return this._y},set(t){if(t==this._y)return;f.watch&&(f.mod[28]=!0);let e=t/this._y;f._h&&(this._h*=e,this._hh*=e),f._resizeColliders({x:1,y:e}),this._y=t,this._avg=.5*(this._x+this._y)}}),this._offset={_x:0,_y:0,get x(){return this._x},set x(t){t!=this._x&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(t-this._x,0))},get y(){return this._y},set y(t){t!=this._y&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(0,t-this._y))}},this._angle=0,this._rotationSpeed=0,this._bearing=0,this.prevPos={x:s,y:r},this.prevRotation=0,this._dest={x:s,y:r},this._destIdx=0,this.drag=0,this.debug=!1,this._shift={};let g=u.vel.x||0,y=u.vel.y||0;"function"==typeof g&&(g=g(u.length-1)),"function"==typeof y&&(y=y(u.length-1)),this.vel.x=g,this.vel.y=y;let m=["ani","collider","vel","x","y","w","h","d","diameter","dynamic","height","kinematic","speed","static","width"];for(let t of this.p.Sprite.propsAll){if(m.includes(t))continue;let e=u[t];void 0!==e&&("function"==typeof e&&p(e)&&(e=e(u.length-1)),this[t]="object"==typeof e?Object.assign({},e):e)}m=["add","animation","animations","autoCull","contains","GroupSprite","Group","idNum","length","mod","mouse","p","parent","Sprite","Subgroup","subgroups","velocity"];for(let t=0;t1?1:50,h??=r),"box"!=a&&"circle"!=a||(l=s(r-.08,h-.08,this.tileSize)),"box"==a)p=e.Box(l.x/2,l.y/2,s(t,i,this.tileSize),0);else if("circle"==a)p=e.Circle(s(t,i,this.tileSize),l.x/2);else if(n){let c,_,f=[{x:0,y:0}],g={x:0,y:0},y={x:0,y:0},m={x:0,y:0},w=Array.isArray(n[0]);function x(){g.xm.x&&(m.x=g.x),g.y>m.y&&(m.y=g.y)}if(w){this._vertexMode&&(c=n[0][0],_=n[0][1],this.body?(c=this.x-this._relativeOrigin.x,_=this.y-this._relativeOrigin.y,f.pop()):(this.x=c,this.y=_));for(let b=0;b0?1:-1;S=Math.abs(S);let C=0;for(let k=0;ke.Settings.maxPolygonVertices||"chain"==this._shape)&&(a="chain"),"polygon"==a?p=e.Polygon(f):"chain"==a&&(p=e.Chain(f,!1))}return this._shape||(this._shape=a),this._w=r,this._hw=.5*r,"circle"==this._shape?this._diameter=r:(this._h=h,this._hh=.5*h),p}removeColliders(){this._collides={},this._colliding={},this._collided={},this._removeFixtures(!1)}removeSensors(){this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._removeFixtures(!0)}_removeFixtures(t){let e;for(let i=this.fixtureList;i;i=i.getNext())if(void 0===t||i.m_isSensor==t){let t=i.m_next;i.destroyProxies(this.p.world.m_broadPhase),e?e.m_next=t:this.body.m_fixtureList=t}else e=i}_offsetCenterBy(t,e){if(!t&&!e)return;if(this._offset._x+=t,this._offset._y+=e,!this.body)return;let i=s(t,e,this.tileSize);for(let t=this.body.m_fixtureList;t;t=t.m_next){let e=t.m_shape;if("circle"!=e.m_type){let t=e.m_vertices;for(let e of t)e.x+=i.x,e.y+=i.y}else e.m_p.x+=i.x,e.m_p.y+=i.y}}_cloneBodyProps(){let t={},e=["bounciness","density","drag","friction","heading","isSuperFast","rotation","rotationDrag","rotationLock","rotationSpeed","scale","vel","x","y"];this._massUndef&&this._dimensionsUndef||e.push("mass");for(let i of e)"object"==typeof this[i]?t[i]=Object.assign({},this[i]):t[i]=this[i];return t}get animation(){return this._ani}set animation(t){this.changeAni(t)}get ani(){return this._ani}set ani(t){this.changeAni(t)}get anis(){return this.animations}get autoDraw(){return this._autoDraw}set autoDraw(t){this.watch&&(this.mod[6]=!0),this._autoDraw=t}get allowSleeping(){return this.body?.isSleepingAllowed()}set allowSleeping(t){this.watch&&(this.mod[7]=!0),this.body&&this.body.setSleepingAllowed(t)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){this.watch&&(this.mod[8]=!0),this._autoUpdate=t}get bounciness(){if(this.fixture)return this.fixture.getRestitution()}set bounciness(t){this.watch&&(this.mod[9]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setRestitution(t)}get centerOfMass(){let t=this.body.getWorldCenter(),e=r(t.x,t.y,this.tileSize);return this.p.createVector(e.x,e.y)}get collider(){return this._collider}set collider(t){let e=(t=t.toLowerCase())[0];if("d"==e&&(t="dynamic"),"s"==e&&(t="static"),"k"==e&&(t="kinematic"),"n"==e&&(t="none"),t==this._collider)return;if(this.__collider=["d","s","k","n"].indexOf(e),void 0===this._collider)return void(this._collider=t);if("none"==t&&("chain"==this._shape||"polygon"==this._shape))throw new Error('Cannot set the collider type of a polygon or chain collider to "none". Try having the sprite overlap with other sprites instead.');this.joints.length&&(this.joints.removeAll(),console.warn("Changing the collider type of a sprite that has joints will remove all its joints.")),this.watch&&(this.mod[10]=!0);let i=this._collider;this._collider=t,void 0!==i&&this._reset()}_reset(){let t,e=this._cloneBodyProps();"chain"!=this._shape&&"polygon"!=this._shape||(t=this._getVertices(!0),this._vertexMode=!0),this.body&&(this.p.world.destroyBody(this.body),this.body=void 0),"none"!=this._collider&&(t?this.addCollider(0,0,t):this.addCollider(),this._hasSensors&&this.addDefaultSensors());for(let t in e)void 0!==e[t]&&(this[t]=e[t]);let i=this._offset._x,s=this._offset._y;this._offset._x=0,this._offset._y=0,this._offsetCenterBy(i,s)}_parseColor(t){if(t instanceof p5.Color)return t;if("object"!=typeof t)return"string"==typeof t&&1==t.length?this.p.colorPal(t):this.p.color(t);if(t.levels)return this.p.color(...t.levels);if(void 0!==t._r)return this.p.color(t._r,t._g,t._b,255*t._a);if(void 0!==t._h)return this.p.color(t._h,t._s,t._v,255*t._a);throw new Error("Invalid color")}get color(){return this._color}set color(t){this.watch&&(this.mod[11]=!0),this._color=this._parseColor(t)}get colour(){return this._color}set colour(t){this.color=t}get fill(){return this._color}set fill(t){this.color=t}get fillColor(){return this._color}set fillColor(t){this.color=t}get stroke(){return this._stroke}set stroke(t){this.watch&&(this.mod[31]=!0),this._stroke=this._parseColor(t)}get strokeColor(){return this._stroke}set strokeColor(t){this.stroke=t}get strokeWeight(){return this._strokeWeight}set strokeWeight(t){this.watch&&(this.mod[32]=!0),this._strokeWeight=t}get textColor(){return this._textColor}set textColor(t){this.watch&&(this.mod[34]=!0),this._textColor=this._parseColor(t)}get bearing(){return this._bearing}set bearing(t){this.watch&&(this.mod[39]=!0),this._bearing=t}get debug(){return this._debug}set debug(t){this.watch&&(this.mod[12]=!0),this._debug=t}get density(){if(this.fixture)return this.fixture.getDensity()}set density(t){this.watch&&(this.mod[13]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setDensity(t)}_getDirectionAngle(t){t=t.toLowerCase().replaceAll(/[ _-]/g,"");let e={up:-90,down:90,left:180,right:0,upright:-45,rightup:-45,upleft:-135,leftup:-135,downright:45,rightdown:45,downleft:135,leftdown:135,forward:this.rotation,backward:this.rotation+180}[t];return"radians"==this.p._angleMode&&(e=this.p.radians(e)),e}get direction(){return 0!==this.vel.x||0!==this.vel.y?this.p.atan2(this.vel.y,this.vel.x):void 0===this._direction?this.rotation:this._direction}set direction(t){this.watch&&(this.mod[14]=!0),"string"==typeof t&&(this._heading=t,t=this._getDirectionAngle(t)),this._direction=t;let e=this.speed;this.vel.x=this.p.cos(t)*e,this.vel.y=this.p.sin(t)*e}get drag(){return this.body?.getLinearDamping()}set drag(t){this.watch&&(this.mod[15]=!0),this.body&&this.body.setLinearDamping(t)}get draw(){return this._display}set draw(t){this._draw=t}get dynamic(){return this.body?.isDynamic()}set dynamic(t){this.collider=t?"dynamic":"kinematic"}get fixture(){return this.fixtureList}get fixtureList(){return this.body?this.body.m_fixtureList:null}get friction(){if(this.fixture)return this.fixture.getFriction()}set friction(t){this.watch&&(this.mod[16]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setFriction(t)}get heading(){return this._heading}set heading(t){this.direction=t}get img(){return this._ani?.frameImage}set img(t){this.changeAni(t)}get image(){return this._ani?.frameImage}set image(t){this.changeAni(t)}get isMoving(){return 0!=this.vel.x||0!=this.vel.y}get isSuperFast(){return this.body?.isBullet()}set isSuperFast(t){this.watch&&(this.mod[18]=!0),this.body&&this.body.setBullet(t)}get kinematic(){return this.body?.isKinematic()}set kinematic(t){this.collider=t?"kinematic":"dynamic"}get layer(){return this._layer}set layer(t){this.watch&&(this.mod[19]=!0),this._layer=t}get life(){return this._life}set life(t){this.watch&&(this.mod[20]=!0),this._life=t}get mass(){return this.body?.getMass()}set mass(t){if(!this.body)return;this.watch&&(this.mod[21]=!0);let e=this.massData;e.mass=t>0?t:1e-8,this.body.setMassData(e),delete this._massUndef}get massData(){const t={I:0,center:new e.Vec2(0,0),mass:0};return this.body.getMassData(t),t.center=r(t.center.x,t.center.y,this.tileSize),t}resetMass(){this.body&&(this.watch&&(this.mod[21]=!0),this.body.resetMassData(),delete this._massUndef)}get mirror(){return this._mirror}set mirror(t){this.watch&&(this.mod[22]=!0),void 0!==t.x&&(this._mirror.x=t.x),void 0!==t.y&&(this._mirror.y=t.y)}get offset(){return this._offset}set offset(t){t.x??=this._offset._x,t.y??=this._offset._y,t.x==this._offset._x&&t.y==this._offset._y||(this.watch&&(this.mod[23]=!0),this._offsetCenterBy(t.x-this._offset._x,t.y-this._offset._y))}get previousPosition(){return this.prevPos}set previousPosition(t){this.prevPos=t}get previousRotation(){return this.prevRotation}set previousRotation(t){this.prevRotation=t}get pixelPerfect(){return this._pixelPerfect}set pixelPerfect(t){this.watch&&(this.mod[24]=!0),this._pixelPerfect=t}get rotation(){if(!this.body)return this._angle||0;let t=this.body.getAngle();return"degrees"===this.p._angleMode?this.p.degrees(t):t}set rotation(t){this.body?("degrees"===this.p._angleMode&&(t=this.p.radians(t)),this.body.setAngle(t)):this._angle=t}get rotationDrag(){return this.body?.getAngularDamping()}set rotationDrag(t){this.body&&(this.watch&&(this.mod[26]=!0),this.body.setAngularDamping(t))}get rotationLock(){return this.body?.isFixedRotation()}set rotationLock(t){this.body&&(this.watch&&(this.mod[27]=!0),this.body.setFixedRotation(t))}get rotationSpeed(){return this.body?this.body.getAngularVelocity():this._rotationSpeed}set rotationSpeed(t){this.body?this.body.setAngularVelocity(t):this._rotationSpeed=t}get scale(){return this._scale}set scale(t){if(t<=0&&(t=.01),"number"==typeof t?t={x:t,y:t}:(t.x??=this._scale._x,t.y??=this._scale._y),t.x==this._scale._x&&t.y==this._scale._y)return;this.watch&&(this.mod[28]=!0);let e={x:t.x/this._scale._x,y:t.y/this._scale._y};this._w*=e.x,this._hw*=e.x,this._h&&(this._h*=e.y,this._hh*=e.y),this._resizeColliders(e),this._scale._x=t.x,this._scale._y=t.y,this._scale._avg=t.x}get sleeping(){if(this.body)return!this.body.isAwake()}set sleeping(t){this.body&&(this.watch&&(this.mod[30]=!0),this.body.setAwake(!t))}get speed(){return this.p.createVector(this.vel.x,this.vel.y).mag()}set speed(t){let e=this.direction;this.vel.x=this.p.cos(e)*t,this.vel.y=this.p.sin(e)*t}get static(){return this.body?.isStatic()}set static(t){this.collider=t?"static":"dynamic"}get removed(){return this._removed}set removed(t){t&&!this._removed&&(this.watch&&(this.mod[25]=!0),this._removed=!0,this._remove())}get vertices(){return this._getVertices()}_getVertices(t){let e=this.fixture;for(;e.m_next&&!e.m_isSensor;)e=e.m_next;let s=e.getShape(),r=[...s.m_vertices];"polygon"==s.m_type&&r.unshift(r.at(-1));let o=this.x,n=this.y;for(let e=0;e=1e3?this.p.p5play.sprites[r]:this.p.p5play.groups[r];let o=i[s][r]+1;if(this[s][r]=o,t instanceof this.p.Group&&(t[s][i._uid]=o),t&&0!=o){if(!(t instanceof this.p.Group)){e=[],1!=o&&-2!=o||e.push(n[s][0]),-1!=o&&e.push(n[s][1]),-1!=o&&-2!=o||e.push(n[s][2]);for(let s of e){let e=this.p.world._findContact(s,i,t,!0);e&&e(i,t,o)}}}else delete i[s][r],t instanceof this.p.Group&&delete t[s][i._uid]}this.removed&&0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}_draw(){if(void 0!==this.strokeWeight&&this.p.strokeWeight(this.strokeWeight),this._ani?.draw&&"colliders"!=this.debug&&this._ani.draw(this._offset._x,this._offset._y,0,this._scale._x,this._scale._y),!this._ani||this.debug||this.p.p5play.disableImages)if(this.debug&&"colliders"!=this.debug&&(this.p.noFill(),this.p.stroke(0,255,0),this.p.line(0,-2,0,2),this.p.line(-2,0,2,0)),3!=this.__collider){"chain"==this._shape?this.p.stroke(this.stroke||this.color):this._stroke&&this.p.stroke(this._stroke);for(let t=this.fixtureList;t;t=t.getNext())t.m_isSensor&&!this.debug||this._drawFixture(t)}else this.p.stroke(this._stroke||120),"box"==this._shape?this.p.rect(this._offset._x,this._offset._y,this.w*this.tileSize,this.h*this.tileSize):"circle"==this._shape&&this.p.circle(this._offset._x,this._offset._y,this.d*this.tileSize);void 0!==this.text&&(this.p.textAlign(this.p.CENTER,this.p.CENTER),this.p.fill(this.textColor),this.p.textSize(this.textSize*this.tileSize),this.p.text(this.text,0,0))}_display(){let t=.5*this.p.width-this.p.world._origin.x+this.x*this.tileSize,e=.5*this.p.height-this.p.world._origin.y+this.y*this.tileSize,i=Math.max(this._w,this._h);if("chain"!=this.shape&&this.p.camera.active&&(t+ithis.p.camera.bound.max.x||e+ithis.p.camera.bound.max.y))this._visible=null;else{this._visible=!0,this.p.p5play.spritesDrawn++,this._pixelPerfect?(t=this._w%2==0?Math.round(t):Math.round(t-.5)+.5,e=this._h%2==0?Math.round(e):Math.round(e-.5)+.5):(t=h(t),e=h(e));for(let t of this.joints)t.visible?this._uid==t.spriteA._uid?(!t.spriteB._visible||this.layer<=t.spriteB.layer)&&t._display():(!t.spriteA._visible||this.layer1?(r=Math.round(r),o=Math.round(o)):e%90==0&&(r=h(r),o=h(o)),this.moveTo(r,o,i)}moveTo(e,i,s){if("number"!=typeof e){let t=e;if(t==this.p.mouse&&!this.p.mouse.active)return;if(!t||void 0===t.x||void 0===t.y)throw"sprite.moveTo ERROR: destination not defined.";s=i,i=t.y,e=t.x}if(this._dest.x=this.x,this._dest.y=this.y,e==this.x?e=!1:(this._dest.x=e,e=!0),i==this.y?i=!1:(this._dest.y=i,i=!0),this._destIdx++,!e&&!i)return Promise.resolve(!0);if(this.speed&&(s??=this.speed),this.tileSize>1&&(s??=.1),s??=1,s<=0)return console.warn("sprite.move: speed should be a positive number"),Promise.resolve(!1);let r=this._dest.y-this.y,o=this._dest.x-this.x,h=s/Math.sqrt(r*r+o*o);this.vel.x=o*h,this.vel.y=r*h;let n=this.direction,a=n-.1,l=n+.1,p=s+.01,d=this._destIdx,u=Math.max(this.p.world.velocityThreshold,.25*p)/this.tileSize;return(async()=>{let s=p+p,r=p+p;do{if(d!=this._destIdx)return!1;await t.delay();let e=this.direction;if(e<=a||e>=l||Math.abs(this.vel.x)<=u&&Math.abs(this.vel.y)<=u)return!1;s=Math.abs(this.x-this._dest.x),r=Math.abs(this.y-this._dest.y)}while(e&&s>p||i&&r>p);return s2&&(i=o[0],s=o[1],e=o[2],r=o[3]),void 0!==i?t=this.angleToFace(i,s,r):t-=this.rotation,e??=.1,this.rotationSpeed=t*e}angleTo(t,e){if("object"==typeof t){let i=t;if(i==this.p.mouse&&!this.p.mouse.active)return 0;if(void 0===i.x||void 0===i.y)return console.error("sprite.angleTo ERROR: rotation destination not defined, object given with no x or y properties"),0;e=i.y,t=i.x}return this.p.atan2(e-this.y,t-this.x)}angleToFace(t,e,i){if("object"==typeof t&&(i=e,e=t.y,t=t.x),Math.abs(t-this.x)<.01&&Math.abs(e-this.y)<.01)return 0;let s=this.angleTo(t,e);i??=0,s+=i;let r=s-this.rotation%360,o=360-Math.abs(r);return o*=r<0?1:-1,Math.abs(r)2&&(i=o[0],s=o[1],e=o[2],r=o[3]),void 0!==i)t=this.angleToFace(i,s,r);else{if(t==this.rotation)return;t-=this.rotation}return this.rotate(t,e)}rotate(e,i){if(1==this.__collider)throw new v(0);if(isNaN(e))throw new v(1,[e]);if(0==e)return;let s=Math.abs(e);i??=1,i>s&&(i=s);let r=this.rotation+e,o=e>0;this.rotationSpeed=i*(o?1:-1);let h=Math.floor(s/i)-1;this._rotateIdx??=0,this._rotateIdx++;let n=this._rotateIdx;return(async()=>{if(h>1){let e=Math.abs(this.rotationSpeed)+.01;do{if(this._rotateIdx!=n)return!1;if(await t.delay(),o&&this.rotationSpeed<.01||!o&&this.rotationSpeed>-.01)return!1}while((o&&r>this.rotation||!o&&r.01&&(this.rotationSpeed=r-this.rotation,await t.delay())}else await t.delay();return this._rotateIdx==n&&(this.rotationSpeed=0,this.rotation=r,!0)})()}async changeAni(t){if(this.p.p5play.disableImages)return;if(arguments.length>1)t=[...arguments];else if(t instanceof this.p.SpriteAnimation){if(t==this._ani)return;t=[t]}else if(!Array.isArray(t)){if(t==this._ani?.name)return;t=[t]}let e,i;this._aniChangeCount++;for(let s=0;s1&&("!"==r.name[0]&&(r.name=r.name.slice(1),r.start=-1,r.end=0),"<"!=r.name[0]&&">"!=r.name[0]||(r.name=r.name.slice(1),r.flipX=!0),"^"==r.name[0]&&(r.name=r.name.slice(1),r.flipY=!0),"**"==r.name&&(e=!0,t=t.slice(0,-1)),";;"==r.name&&(i=!0,t=t.slice(0,-1)))}let s=this._aniChangeCount;do{for(let e=0;e1&&(i.start=0),await this._playSequencedAni(i)}}while(e&&s==this._aniChangeCount);1!=t.length&&i&&this._ani.stop()}_playSequencedAni(t){return new Promise((e=>{let{name:i,start:s,end:r,flipX:o,flipY:h}=t;this._changeAni(i),o&&(this._ani.scale.x=-this._ani.scale.x),h&&(this._ani.scale.y=-this._ani.scale.y),s<0&&(s=this._ani.length+s),void 0!==s&&(this._ani.frame=s),void 0!==r?this._ani.goToFrame(r):this._ani.frame==this._ani.lastFrame&&e(),this._ani._onComplete=this._ani._onChange=()=>{o&&(this._ani.scale.x=-this._ani.scale.x),h&&(this._ani.scale.y=-this._ani.scale.y),this._ani._onComplete=this._ani._onChange=null,e()}}))}changeAnimation(){return this.changeAni(...arguments)}_changeAni(t){this._ani?._onChange&&this._ani._onChange(),this._ani?.onChange&&this._ani.onChange();let e=this.animations[t];if(!e)for(let i=this.groups.length-1;i>=0;i--){if(e=this.groups[i].animations[t],e){e=e.clone();break}}if(!e)throw this.p.noLoop(),new v("Sprite.changeAnimation",[t]);this._ani=e,this._ani.name=t,this.resetAnimationsOnChange&&(this._ani.frame=0)}remove(){this.removed=!0}_remove(){this.body&&this.p.world.destroyBody(this.body),this.body=null;for(let t of this.groups)t.remove(this);0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}toString(){return"s"+this.idNum}_ensureCollide(t,e){if(!t)throw new v("Sprite.collide",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.collide",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.collide",1,[e]);if(!1!==this._hasOverlap[t._uid]&&(this._hasOverlap[t._uid]=!1),!1!==t._hasOverlap[this._uid]&&(t._hasOverlap[this._uid]=!1,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!1}collide(t,e){return this.collides(t,e)}collides(t,e){return this._ensureCollide(t,e),this._collides[t._uid]=e||!0,1==this._collisions[t._uid]}colliding(t,e){this._ensureCollide(t,e),this._colliding[t._uid]=e||!0;let i=this._collisions[t._uid];return i>0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){if(t instanceof this.p.Group)for(let e of t)this._removeContactsWith(e);else this.__removeContactsWith(t)}__removeContactsWith(t){if(this.body)for(let e=this.body.getContactList();e;e=e.next){let i=e.contact;i.m_fixtureA.m_body.sprite._uid!=t._uid&&i.m_fixtureB.m_body.sprite._uid!=t._uid||this.p.world.destroyContact(i)}}_ensureOverlap(t,e){if(!t)throw new v("Sprite.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.overlap",1,[e]);if(this._hasSensors||this.addDefaultSensors(),!t._hasSensors)if(t instanceof this.p.Sprite)t.addDefaultSensors();else{for(let e of t)e._hasSensors||e.addDefaultSensors();t._hasSensors=!0}if(1!=this._hasOverlap[t._uid]&&(this._removeContactsWith(t),this._hasOverlap[t._uid]=!0),1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}_sortFixtures(){let t=null,e=null;for(let i=this.fixtureList;i;i=i.getNext())i.m_isSensor?e?e.m_next=i:e=i:t?t.m_next=i:t=i;e&&(e.m_next=null),t&&(t.m_next=e),this.body.m_fixtureList=t||e}addDefaultSensors(){let t;if(this.body){for(let e=this.fixtureList;e;e=e.getNext())e.m_isSensor||(t=e.m_shape,this.body.createFixture({shape:t,isSensor:!0}));this._sortFixtures()}else this.addSensor();this._hasSensors=!0}},this.Sprite.propTypes={x:"Float64",y:"Float64",vel:"Vec2",rotation:"number",rotationSpeed:"number",ani:"string",autoDraw:"boolean",allowSleeping:"boolean",autoUpdate:"boolean",bounciness:"number",collider:"Uint8",color:"color",debug:"boolean",density:"number",direction:"number",drag:"number",friction:"number",h:"number",isSuperFast:"boolean",layer:"number",life:"Int32",mass:"number",mirror:"Vec2_boolean",offset:"Vec2",pixelPerfect:"boolean",removed:"boolean",rotationDrag:"number",rotationLock:"boolean",scale:"Vec2",shape:"Uint8",sleeping:"boolean",stroke:"color",strokeWeight:"number",text:"string",textColor:"color",tile:"string",tileSize:"number",visible:"boolean",w:"number",bearing:"number"},this.Sprite.props=Object.keys(this.Sprite.propTypes),this.Sprite.propsAll=this.Sprite.props.concat(["d","diameter","dynamic","fill","height","heading","kinematic","resetAnimationsOnChange","speed","static","width"]),this.Sprite.colliderTypes=["d","s","k","n"],this.Sprite.shapeTypes=["box","circle","chain","polygon"],this.Turtle=function(e){if(t.allSprites.tileSize>1)throw new Error("Turtle can't be used when allSprites.tileSize is greater than 1.");e??=25;let i=new t.Sprite(e,e,[[e,.4*e],[-e,.4*e],[0,.8*-e]]);i.color="green",i._isTurtleSprite=!0,i._prevPos={x:i.x,y:i.y};let s=i.move;return i.move=async function(){this._prevPos.x=this.x,this._prevPos.y=this.y,await s.call(this,...arguments)},i},this.SpriteAnimation=class extends Array{constructor(){super(),this.p=t;let e,i=[...arguments];if(this.name="default",(i[0]instanceof this.p.Sprite||i[0]instanceof this.p.Group)&&(e=i[0],i=i.slice(1),this._addedToSpriteOrGroup=!0),e??=this.p.allSprites,"string"!=typeof i[0]||1!=i[0].length&&i[0].includes(".")||(this.name=i[0],i=i.slice(1)),this.frame=0,this._cycles=0,this.targetFrame=-1,this.offset={x:e.anis.offset.x||0,y:e.anis.offset.y||0},this._frameDelay=e.anis.frameDelay||4,this.demoMode=e.anis.demoMode||!1,this.playing=!0,this.visible=!0,this.looping=e.anis.looping,this.looping??=!0,this.endOnFirstFrame=!1,this.frameChanged=!1,this.onComplete=this.onChange=null,this._onComplete=this._onChange=null,this.rotation=e.anis.rotation||0,this._scale=new l,0!=i.length&&"number"!=typeof i[0])if(e.animations[this.name]=this,e._ani=this,Array.isArray(i[0])&&"string"==typeof i[0][0]&&(i=[...i[0]]),2!=i.length||"string"!=typeof i[0]||"string"!=typeof i[1]&&"number"!=typeof i[1])if("string"==typeof i[i.length-1]||i[i.length-1]instanceof p5.Image)for(let s=0;s=3)throw new v("SpriteAnimation",1);o=i[0],r=i[1]}else r=i[0];let h=this;if(o instanceof p5.Image&&1!=o.width&&1!=o.height)this.spriteSheet=o,n();else{let a;a="string"==typeof o?o:o.url,this.spriteSheet=this.p.loadImage(a,(()=>{n()}))}function n(){if(Array.isArray(r)||Array.isArray(r.frames)){if("number"!=typeof r[0]){let t=r;if(Array.isArray(r.frames)){t=r.frames,delete r.frames;for(let e=0;e=h.spriteSheet.width&&(u=0,c+=i,c>=h.spriteSheet.height&&(c=0))}}else{let p,d,u=i[0];if(isNaN(i[1])?p=i[1]:d=Number(i[1]),".png"!=u.slice(-4)||p&&".png"!=p.slice(-4))throw new v("SpriteAnimation",0,[u]);let c=0,_=0;for(let y=u.length-5;y>=0&&!isNaN(u.charAt(y));y--)c++;if(p)for(let m=p.length-5;m>=0&&!isNaN(p.charAt(m));m--)_++;let f,g=u.slice(0,-4-c);if(p&&(f=p.slice(0,-4-_)),p&&g!=f)this.push(this.p.loadImage(u)),this.push(this.p.loadImage(p));else{let w,x=parseInt(u.slice(-4-c,-4),10);if(d??=parseInt(p.slice(-4-_,-4),10),dthis.frame&&-1!==this.targetFrame?this.frame++:this.targetFrame=this.lastFrame?this.frame=0:this.frame++:this.frame{this._onComplete=()=>{this._onComplete=null,t()}}))}pause(t){this.playing=!1,t&&(this.frame=t)}stop(t){this.playing=!1,t&&(this.frame=t)}rewind(){return this.looping=!1,this.goToFrame(0)}loop(){this.looping=!0,this.playing=!0}noLoop(){this.looping=!1}nextFrame(){this.frame0?this.frame=this.frame-1:this.looping&&(this.frame=this.length-1),this.targetFrame=-1,this.playing=!1}goToFrame(t){if(!(t<0||t>=this.length))return this.targetFrame=t,this.targetFrame!==this.frame&&(this.playing=!0),new Promise((t=>{this._onComplete=()=>{this._onComplete=null,t()}}))}get lastFrame(){return this.length-1}get frameImage(){let t=this[this.frame];if(t instanceof p5.Image)return t;let{x:e,y:i,w:s,h:r}=t,o=createGraphics(s,r);return o.image(this.spriteSheet,this.offset.x,this.offset.y,s,r,e,i,s,r),o}get w(){return this.width}get width(){return this[this.frame]instanceof p5.Image?this[this.frame].width:this[this.frame]?this[this.frame].w:1}get h(){return this.height}get height(){return this[this.frame]instanceof p5.Image?this[this.frame].height:this[this.frame]?this[this.frame].h:1}get frames(){let t=[];for(let e=0;ee.#t[t],set(i){e.#t[t]=i;for(let s in e){let r=e[s];r instanceof SpriteAnimation&&(r[t]=i)}}});for(let t of s){this.#t[t]={_x:0,_y:0};for(let i of["x","y"])Object.defineProperty(this.#t[t],i,{get:()=>e.#t[t]["_"+i],set(s){e.#t[t]["_"+i]=s;for(let r in e){let o=e[r];o instanceof SpriteAnimation&&(o[t][i]=s)}}})}}},this.Group=class extends Array{constructor(...e){let i;if(e[0]instanceof t.Group&&(i=e[0],e=e.slice(1)),super(...e),this.p=t,"number"==typeof e[0])return;for(let t of this)if(!(t instanceof this.p.Sprite))throw new Error("A group can only contain sprites");if(this.x,this.y,this.vel,this.rotation,this.rotationSpeed,this.autoDraw,this.allowSleeping,this.autoUpdate,this.bounciness,this.collider,this.color,this.debug,this.density,this.direction,this.drag,this.friction,this.h,this.isSuperFast,this.layer,this.life,this.mass,this.mirror,this.offset,this.pixelPerfect,this.removed,this.rotationDrag,this.rotationLock,this.scale,this.shape,this.sleeping,this.stroke,this.strokeWeight,this.text,this.textColor,this.tile,this.tileSize,this.visible,this.w,this.bearing,this.d,this.diameter,this.dynamic,this.height,this.heading,this.kinematic,this.resetAnimationsOnChange,this.speed,this.static,this.width,this.idNum=this.p.p5play.groupsCreated,this._uid=this.idNum,this.p.p5play.groups[this._uid]=this,this.p.p5play.groupsCreated++,this.p.allSprites||(this._isAllSpritesGroup=!0),this.subgroups=[],i instanceof this.p.Group){i.subgroups.push(this);let t=i;do{t=this.p.p5play.groups[t.parent],t.subgroups.push(this)}while(!t._isAllSpritesGroup);this.parent=i._uid}else this._isAllSpritesGroup||(this.p.allSprites.subgroups.push(this),this.parent=0);this.animations=new this.p.SpriteAnimations,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={};let s=this;this.Sprite,this.Sprite=class extends this.p.Sprite{constructor(){super(s,...arguments)}},this.GroupSprite=this.Sprite,this.Group,this.Group=class extends this.p.Group{constructor(){super(s,...arguments)}},this.Subgroup=this.Group,this.mouse={presses:null,pressing:null,pressed:null,holds:null,holding:null,held:null,released:null,hovers:null,hovering:null,hovered:null};for(let t in this.mouse)this.mouse[t]=function(e){for(let i of s)if(i.mouse[t](e))return!0;return!1};let r=[...this.p.Sprite.propsAll,"spriteSheet"];for(let t of r)"ani"!=t&&"velocity"!=t&&Object.defineProperty(this,t,{get(){let e=s["_"+t],i=s.length-1;if(void 0===e&&!s._isAllSpritesGroup){let r=this.p.p5play.groups[s.parent];r&&(e=r[t],i=r.length-1)}return e},set(e){s["_"+t]=e;for(let i=0;it&&(t=e._layer);return t}get ani(){return this._ani}set ani(t){this.addAni(t);for(let e of this)e.changeAni(t)}get animation(){return this._ani}set animation(t){this.ani=t}get anis(){return this.animations}get img(){return this._ani.frameImage}set img(t){this.ani=t}get image(){return this._ani.frameImage}set image(t){this.ani=t}set amount(t){let e=t-this.length,i=e>0;e=Math.abs(e);for(let t=0;t0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){for(let e of this)e._removeContactsWith(t)}_ensureOverlap(t,e){if(!t)throw new v("Group.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Group.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Group.overlap",1,[e]);if(!this._hasSensors){for(let t of this)t._hasSensors||t.addDefaultSensors();this._hasSensors=!0}if(!t._hasSensors)if(t instanceof this.p.Sprite)t.addDefaultSensors();else{for(let e of t)e._hasSensors||e.addDefaultSensors();t._hasSensors=!0}if(1!=this._hasOverlap[t._uid]){this._removeContactsWith(t),this._hasOverlap[t._uid]=!0;for(let e of this)e._hasOverlap[t._uid]=!0}if(1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}applyForce(){for(let t of this)t.applyForce(...arguments)}applyForceScaled(){for(let t of this)t.applyForceScaled(...arguments)}attractTo(){for(let t of this)t.attractTo(...arguments)}applyTorque(){for(let t of this)t.applyTorque(...arguments)}move(t,e,i){let s=[];for(let r of this)s.push(r.move(t,e,i));return Promise.all(s)}moveTo(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}let s=this._resetCentroid(),r=[];for(let o of this){let h={x:o.x-s.x+t,y:o.y-s.y+e};r.push(o.moveTo(h.x,h.y,i))}return Promise.all(r)}moveTowards(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveTowards(r.x,r.y,i)}}}moveAway(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveAway(r.x,r.y,i)}}}push(...t){for(let e of t){if(!(e instanceof this.p.Sprite))throw new Error("you can only add sprites to a group, no "+typeof e+"s");for(let t in this._hasOverlap){let i=this._hasOverlap[t];i&&!e._hasSensors&&e.addDefaultSensors(),e._hasOverlap[t]=i}super.push(e),this.parent&&this.p.p5play.groups[this.parent].push(e),e.groups.push(this)}return this.length}size(){return this.length}toString(){return"g"+this.idNum}cull(t,e,i,s,r){if(void 0===i){r=e,t=e=i=s=t}if(isNaN(t)||isNaN(e)||isNaN(i)||isNaN(s))throw new TypeError("The culling boundary must be defined with numbers");if(r&&"function"!=typeof r)throw new TypeError("The callback to group.cull must be a function");let o=this.p.camera.x-this.p.world.hw/this.p.camera.zoom,h=this.p.camera.y-this.p.world.hh/this.p.camera.zoom,n=-i+o,a=-t+h,l=this.p.width+s+o,p=this.p.height+e+h,d=0;for(let t=0;tl||e.y>p)&&(d++,r?r(e,d):e.remove(),e.removed&&t--))}return d}remove(t){if(void 0===t){for(;this.length>0;)this[0].remove();return}let e;if(e="number"==typeof t?t>=0?t:this.length+t:this.indexOf(t),-1!=e){let t=this[e];if(!t.removed){let e=t.groups.findIndex((t=>t._uid==this._uid));t.groups.splice(e,1)}return this.splice(e,1),t}throw new Error("Sprite not found in group")}removeAll(){this.remove()}draw(){let t=[...this];t.sort(((t,e)=>t._layer-e._layer));for(let e=0;e(t.getShape().testPoint(t.getBody().getTransform(),h)&&a.push(t),!0))),r??=this.p.allSprites;let l=[];if(a.length>0)for(let t of r)t.body&&a.includes(t.body.m_fixtureList)&&t._cameraActiveWhenDrawn==o&&l.push(t);return l}getSpriteAt(t,e,i){let s=this.getSpritesAt(t,e,i);return s.sort(((t,e)=>-1*(t._layer-e._layer))),s[0]}_beginContact(t){let e=t.m_fixtureA,i=t.m_fixtureB,s="_collisions";e.m_isSensor&&(s="_overlappers"),e=e.m_body.sprite,i=i.m_body.sprite,e[s][i._uid]=0,i[s][e._uid]=0;for(let t of i.groups)(!e[s][t._uid]||e[s][t._uid]<0)&&(t[s][e._uid]=0,e[s][t._uid]=0);for(let t of e.groups){(!i[s][t._uid]||i[s][t._uid]<0)&&(t[s][i._uid]=0,i[s][t._uid]=0);for(let e of i.groups)(!t[s][e._uid]||t[s][e._uid]<0)&&(t[s][e._uid]=0,e[s][t._uid]=0)}}_endContact(t){let e=t.m_fixtureA,i=t.m_fixtureB,s="_collisions";e.m_isSensor&&(s="_overlappers"),e=e.m_body.sprite,i=i.m_body.sprite,e[s][i._uid]=0!=e[s][i._uid]?-2:-3,i[s][e._uid]=0!=i[s][e._uid]?-2:-3;for(let t of i.groups){let i=!1;for(let r of t)if(r[s][e._uid]>=0){i=!0;break}i||(t[s][e._uid]=0!=t[s][e._uid]?-2:-3,e[s][t._uid]=0!=e[s][t._uid]?-2:-3)}for(let t of e.groups){let e=!1;for(let r of t)if(r[s][i._uid]>=0){e=!0;break}if(!e){t[s][i._uid]=0!=t[s][i._uid]?-2:-3,i[s][t._uid]=0!=i[s][t._uid]?-2:-3;for(let e of i.groups)t[s][e._uid]=0!=t[s][e._uid]?-2:3,e[s][t._uid]=0!=e[s][t._uid]?-2:3}}}_findContact(t,e,i,s){let r=e[t][i._uid];if(r&&(!s||!0!==r))return r;let o=i instanceof this.p.Sprite;if(o)for(let o of i.groups)if(r=e[t][o._uid],r&&(!s||!0!==r))return r;if(e instanceof this.p.Sprite)for(let h of e.groups){if(r=h[t][i._uid],r&&(!s||!0!==r))return r;if(o)for(let o of i.groups)if(r=h[t][o._uid],r&&(!s||!0!==r)&&(h._uid!=o._uid||e._uid{for(let t=0;t0&&(t=t<.1?this.p.map(t,0,.1,30,4):t<.5?this.p.map(t,.1,.5,4,2.5):t<.8?this.p.map(t,.5,.8,2.5,1):t<.9?this.p.map(t,.8,.9,1,.5):this.p.map(t,.9,1,.5,.2)),this._springiness=t,"wheel"==this.type?this._j.setSpringFrequencyHz(t):this._j.setFrequency(t)}get damping(){return"wheel"!=this.type?this._j.getDampingRatio():this._j.getSpringDampingRatio()}set damping(t){"wheel"==this.type?this._j.setSpringDampingRatio(t):this._j.setDampingRatio(t)}get speed(){return this._j.getJointSpeed()}set speed(t){this._j.isMotorEnabled()||this._j.enableMotor(!0),this._j.setMotorSpeed(t)}get motorSpeed(){return this._j.getMotorSpeed()}get enableMotor(){return this._j.isMotorEnabled()}set enableMotor(t){this._j.enableMotor(t)}get maxPower(){return this._j.getMaxMotorTorque()}set maxPower(t){!this._j.isMotorEnabled()&&t&&this._j.enableMotor(!0),this._j.setMaxMotorTorque(t),t||this._j.enableMotor(!1)}get power(){return this._j.getMotorTorque()}get collideConnected(){return this._j.getCollideConnected()}set collideConnected(t){this._j.m_collideConnected=t}remove(){this._removed||(this.spriteA.joints.splice(this.spriteA.joints.indexOf(this),1),this.spriteB.joints.splice(this.spriteB.joints.indexOf(this),1),this.p.world.destroyJoint(this._j),this._removed=!0)}},this.GlueJoint=class extends this.Joint{constructor(t,e){super(...arguments,"glue")}},this.DistanceJoint=class extends this.Joint{constructor(t,i){super(...arguments,"distance");let s=e.DistanceJoint({},t.body,i.body,t.body.getWorldCenter(),i.body.getWorldCenter());this._createJoint(s)}_display(){let t,e;(this.offsetA.x||this.offsetA.y)&&(t=this.spriteA.body.getWorldPoint(this._j.m_localAnchorA),t=r(t.x,t.y,this.spriteA.tileSize)),(this.offsetB.x||this.offsetB.y)&&(e=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB),e=r(e.x,e.y,this.spriteB.tileSize)),this._draw(t?t.x:this.spriteA.x,t?t.y:this.spriteA.y,e?e.x:this.spriteB.x,e?e.y:this.spriteB.y),this.visible=null}},this.WheelJoint=class extends this.Joint{constructor(t,i){super(...arguments,"wheel");let s=e.WheelJoint({maxMotorTorque:1e3,frequencyHz:4,dampingRatio:.7},t.body,i.body,i.body.getWorldCenter(),new e.Vec2(0,1));this._createJoint(s),this._angle="degrees"==this.p._angleMode?90:1.5707963267948966}_display(){let t,e,i=this.spriteA.x,s=this.spriteA.y;if(this.offsetB.x||this.offsetB.y){let i=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB);i=r(i.x,i.y,this.spriteB.tileSize),t=i.x,e=i.y}else t=this.spriteB.x,e=this.spriteB.y;let o=this.p.tan(this.spriteA.rotation),h=this.p.tan(this._angle+this.spriteA.rotation),n=(e-s+o*i-h*t)/(o-h),a=o*(n-i)+s;this._draw(n,a,t,e),this.visible=null}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new e.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=e.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}},this.HingeJoint=class extends this.Joint{constructor(t,i){super(...arguments,"hinge");let s=e.RevoluteJoint({},t.body,i.body,t.body.getWorldCenter());this._createJoint(s)}_display(){const t=this.offsetA.x,e=this.offsetA.y,i=this.spriteA.rotation,s=t*this.p.cos(i)-e*this.p.sin(i),r=t*this.p.sin(i)+e*this.p.cos(i);this._draw(this.spriteA.x+s,this.spriteA.y+r),this.visible=null}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){let t=this._j.getLowerLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_lowerAngle=t}get upperLimit(){let t=this._j.getUpperLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_upperAngle=t}get angle(){let e=this._j.getJointAngle();return"radians"==this.p._angleMode?e:t.radians(e)}},this.RevoluteJoint=this.HingeJoint,this.SliderJoint=class extends this.Joint{constructor(t,i){super(...arguments,"slider");let s=e.PrismaticJoint({lowerTranslation:-1,upperTranslation:1,enableLimit:!0,maxMotorForce:50,motorSpeed:0,enableMotor:!0},t.body,i.body,t.body.getWorldCenter(),new e.Vec2(1,0));this._createJoint(s),this._angle=0}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new e.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=e.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){return this._j.getLowerLimit()/this.spriteA.tileSize*i}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/i,this._j.setLimits(t,this._j.getUpperLimit())}get upperLimit(){return this._j.getUpperLimit()/this.spriteA.tileSize*i}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/i,this._j.setLimits(this._j.getLowerLimit(),t)}},this.PrismaticJoint=this.SliderJoint,this.RopeJoint=class extends this.Joint{constructor(t,i){super(...arguments,"rope");let s=e.RopeJoint({maxLength:1},t.body,i.body,t.body.getWorldCenter());this._createJoint(s),this._j.m_localAnchorB.x=0,this._j.m_localAnchorB.y=0}get maxLength(){return t=this._j.getMaxLength(),e=this.spriteA.tileSize,t/e*i;var t,e}set maxLength(t){var e,s;this._j.setMaxLength((e=t,s=this.spriteA.tileSize,e*s/i))}};class l{constructor(){let t=this;Object.defineProperties(this,{x:{get:()=>t._x,set(e){e!=t._x&&(t._x=e,t._avg=.5*(t._x+t._y))},configurable:!0,enumerable:!0},y:{get:()=>t._y,set(e){e!=t._y&&(t._y=e,t._avg=.5*(t._x+t._y))},configurable:!0,enumerable:!0},_x:{value:1,enumerable:!1,writable:!0},_y:{value:1,enumerable:!1,writable:!0},_avg:{value:1,enumerable:!1,writable:!0}})}valueOf(){return this._avg}}!function(){let t=new Float32Array(1),e=new Int32Array(t.buffer)}();function p(t){return!/^(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*(?:(?:(?:async\s(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*)?function|class)(?:\s|(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*)|(?:[_$\w][\w0-9_$]*\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\()|(?:\[\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*(?:(?:['][^']+['])|(?:["][^"]+["]))\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\]\())/.test(t.toString())}function d(t,e){return"triangle"==e?t=[t,-120,3]:"square"==e?t=[t,-90,4]:"pentagon"==e?t=[t,-72,5]:"hexagon"==e?t=[t,-60,6]:"septagon"==e?t=[t,-51.4285714286,7]:"octagon"==e?t=[t,-45,8]:"enneagon"==e?t=[t,-40,9]:"decagon"==e?t=[t,-36,10]:"hendecagon"==e?t=[t,-32.7272727273,11]:"dodecagon"==e&&(t=[t,-30,12]),t}this.p5play.palettes??=[{a:"aqua",b:"black",c:"crimson",d:"darkviolet",e:"peachpuff",f:"olive",g:"green",h:"hotpink",i:"indigo",j:"navy",k:"khaki",l:"lime",m:"magenta",n:"brown",o:"orange",p:"pink",q:"turquoise",r:"red",s:"skyblue",t:"tan",u:"blue",v:"violet",w:"white",x:"gold",y:"yellow",z:"gray"}],this.colorPal=(e,i)=>{if(e instanceof p5.Color)return e;let s;return"number"==typeof i&&(i=t.p5play.palettes[i]),i??=t.p5play.palettes[0],i&&(s=i[e]),""===s||"."===e||" "===e?t.color(0,0,0,0):t.color(s||e)},this.spriteArt=(e,i,s)=>{i??=1,"number"==typeof s&&(s=t.p5play.palettes[s]),s??=t.p5play.palettes[0];let r=e;"string"==typeof e&&(r=(e=(e=(e=e.trim()).replace(/\r*\n\t+/g,"\n")).replace(/\s+$/g,"")).split("\n"));let o=0;for(let t of r)t.length>o&&(o=t.length);let h=r.length,n=t.createImage(o*i,h*i);n.loadPixels();for(let t=0;tnew Promise(t?e=>{setTimeout(e,t)}:requestAnimationFrame),this.sleep=t=>this.delay(t),this.play=t=>{if(!t.play)throw new Error("Tried to play your input but it wasn't a sound object: "+t);return new Promise(((e,i)=>{t.play(),t.onended((()=>e()))}))},this.p5play.playIntro=async function(){if(document.getElementById("p5play-intro"))return;t._incrementPreload();let e=document.createElement("div");e.id="p5play-intro",e.style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 1000; background-color: black;";let i=document.createElement("img");i.src="https://p5play.org/v3/made_with_p5play.png",i.style="position: absolute; top: 50%; left: 50%; width: 40vh; height: 20vh; margin-left: -20vh; margin-top: -10vh; z-index: 1000; opacity: 0; transition: opacity 0.1s ease-in-out;",document.body.append(e),e.append(i),await t.delay(100),i.style.opacity="1",i.style.transition="scale 1.4s, opacity 0.4s ease-in-out",i.style.scale="1.1",await t.delay(1100),i.style.opacity="0",await t.delay(300),e.style.display="none",e.remove(),document.getElementById("p5play-intro")?.remove(),t._decrementPreload()};{let t=location.hostname;switch(t){case"":case"127.0.0.1":case"localhost":case"p5play.org":case"editor.p5js.org":case"codepen.io":case"codera.app":case"cdpn.io":case"glitch.com":case"replit.com":case"stackblitz.com":case"jsfiddle.net":case"aijs-912fe.web.app":break;default:if(/^[\d\.]+$/.test(t)||t.endsWith("stackblitz.io")||t.endsWith("glitch.me")||t.endsWith("repl.co")||t.endsWith("codehs.com")||t.endsWith("openprocessing.org")||location.origin.endsWith("preview.p5js.org"))break;this.p5play.playIntro()}}let u=p5.disableFriendlyErrors;p5.disableFriendlyErrors=!0,this.canvas=this.canvas;const c=this.createCanvas;this.createCanvas=function(){let e,i,s,r,o=[...arguments],h=!1,n=!1;if("string"==typeof o[0]&&(o[0].includes(":")?s=o[0].split(":"):(o[2]=o[0],o[0]=void 0),"fullscreen"==o[1]&&(h=!0)),o[0]?"number"==typeof o[0]&&"number"!=typeof o[1]&&(o[2]=o[1],o[1]=o[0]):(o[0]=window.innerWidth,o[1]=window.innerHeight,h=!0),"string"==typeof o[2]){let t=o[2].toLowerCase();"p2d"!=t&&"webgl"!=t&&(t=t.split(" "),o.pop()),"pixelated"==t[0]&&(n=!0,t[1]?r=Number(t[1].slice(1)):h=!0,s=[o[0],o[1]]),"fullscreen"==t[0]&&(h=!0)}if(s){let t=Number(s[0]),h=Number(s[1]);r?(e=t*r,i=h*r):(e=window.innerWidth,i=window.innerWidth*(h/t),i>window.innerHeight&&(e=window.innerHeight*(t/h),i=window.innerHeight)),e=Math.round(e),i=Math.round(i),n||(o[0]=e,o[1]=i)}let a=c.call(t,...o);this.canvas.tabIndex=0,this.canvas.w=o[0],this.canvas.h=o[1],this.canvas.addEventListener("keydown",(function(t){" "!=t.key&&"/"!=t.key&&"ArrowUp"!=t.key&&"ArrowDown"!=t.key&&"ArrowLeft"!=t.key&&"ArrowRight"!=t.key||t.preventDefault()})),this.canvas.addEventListener("mouseover",(()=>{this.mouse.isOnCanvas=!0,this.mouse.active=!0})),this.canvas.addEventListener("mouseleave",(()=>{this.mouse.isOnCanvas=!1})),this.canvas.addEventListener("touchstart",(t=>t.preventDefault())),this.canvas.addEventListener("contextmenu",(t=>t.preventDefault())),this.canvas.resize=this.resizeCanvas,this.world.resize(),this.camera.x=this.world.hw,this.camera.y=this.world.hh,u||(p5.disableFriendlyErrors=!1);let l="\n.p5Canvas, .q5Canvas {\n\toutline: none;\n\t-webkit-touch-callout: none;\n\t-webkit-text-size-adjust: none;\n\t-webkit-user-select: none;\n\toverscroll-behavior: none;\n}\nmain {\n\toverscroll-behavior: none;\n}";h&&(l="html,\nbody,\n"+l,l+="\nhtml, body {\n\tmargin: 0;\n\tpadding: 0;\n\toverflow: hidden;\n\theight: 100%;\n}\nmain {\n\tmargin: auto;\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\talign-content: center;\n\tjustify-content: center;\n\theight: 100%;\n}"),n&&(l+=`\n#${this.canvas.id} {\n\timage-rendering: pixelated;\n\twidth: ${e}px!important;\n\theight: ${i}px!important;\n}`);let p=document.createElement("style");p.innerHTML=l,document.head.appendChild(p),n&&(t.pixelDensity(1),t.noSmooth());let d=navigator.userAgent.indexOf("iPhone OS");if(d>-1){let e=navigator.userAgent.substring(d+10,d+12);this.p5play.version=e,e<16&&t.pixelDensity(1),this.p5play.os.platform="iOS",this.p5play.os.version=e}else void 0!==navigator.userAgentData&&(this.p5play.os.platform=navigator.userAgentData.platform);return a},this.Canvas=class{constructor(t,e,i){}get w(){}get width(){}get h(){}get height(){}resize(){}},this.Canvas=function(){return t.createCanvas(...arguments)};const _=this.resizeCanvas;this.resizeCanvas=(t,e)=>{_.call(this,t,e),this.world.resize(),this.camera._pos.x=this.world.hw,this.camera._pos.y=this.world.hh};const f=this.background;this.background=function(){let t,e=arguments;1==e.length&&("string"==typeof e[0]||e[0]instanceof p5.Color)&&(t=this.colorPal(e[0])),void 0!==t?f.call(this,t):f.call(this,...e)};const g=this.fill;this.fill=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?g.call(this,t):g.call(this,...e)};const y=this.stroke;this.stroke=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?y.call(this,t):y.call(this,...e)},this.p5play.images={onLoad:t=>{}},this.p5play.disableImages=!1;const m=this.loadImage;this.loadImage=this.loadImg=function(){if(this.p5play.disableImages)return t._decrementPreload(),{w:16,width:16,h:16,height:16,pixels:[]};let e,i=arguments,s=i[0],r=t.p5play.images[s];if("function"==typeof i[i.length-1]&&(e=i[i.length-1]),r)return 1==r.width&&1==r.height||!r.pixels.length?e?(r.cbs.push(e),r.calls++):t._decrementPreload():(e&&e(),t._decrementPreload()),r;return r=m.call(t,s,(e=>{e.w=e.width,e.h=e.height;for(let t of e.cbs)t(e);for(let i=1;ii[e])),o+=h,p5._friendlyError(o,t)}}this.allSprites=new this.Group,this.world=new this.World,this.camera=new this.Camera,this.InputDevice=class{constructor(){this.holdThreshold=12,this._default=0}_init(t){for(let e of t)this[e]=0}_ac(t){return t}presses(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),1==this[t]||-2==this[t]}pressing(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),-2==this[t]?1:this[t]>0?this[t]:0}pressed(t){return this.released(t)}holds(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]==this.holdThreshold}holding(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]>=this.holdThreshold?this[t]:0}held(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),-3==this[t]}released(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]<=-1}releases(t){return this.released(t)}},this._Mouse=class extends this.InputDevice{constructor(){super(),this._default="left";let t=this;this._position={get x(){return t.x},set x(e){t.x=e},get y(){return t.y},set y(e){t.y=e}},this.x,this.y,this.left,this.center,this.right;this._init(["x","y","left","center","right"]),this.drag={left:0,center:0,right:0},this.isOnCanvas=!1,this.active=!1,this._visible=!0,this._cursor="default"}_ac(t){return"left"==(t=t.toLowerCase()).slice(0,4)?t="left":"right"==t.slice(0,5)?t="right":"middle"==t.slice(0,6)&&(t="center"),t}get pos(){return this._position}get position(){return this._position}get cursor(){return t.canvas.style.cursor}set cursor(e){e!=this._cursor&&(t.cursor(e),this._cursor=e)}get visible(){return this._visible}set visible(e){this._visible=e,t.canvas.style.cursor=e?"default":"none"}drags(t){return t??=this._default,1==this.drag[t]}dragging(t){return t??=this._default,this.drag[t]>0?this.drag[t]:0}dragged(t){return t??=this._default,-1==this.drag[t]}},this.mouse=new this._Mouse,this._SpriteMouse=class extends this._Mouse{constructor(){super(),this.hover=0}hovers(){return 1==this.hover}hovering(){return this.hover>0?this.hover:0}hovered(){return-1==this.hover}};const b=function(t){if(this.mouse[t]++,this.mouse.active=!0,this.world.mouseSprites.length){let e=this.world.mouseSprite;e&&(e.mouse[t]=0,e.mouse.drag[t]=0),e=this.world.mouseSprites[0],e.mouse[t]=1,this.world.mouseSprite=e}},S=t._onmousedown;t._onmousedown=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),b.call(this,e),S.call(this,t)};const A=t._ontouchstart;t._ontouchstart=function(t){b.call(this,"left"),A.call(this,t)};const C=function(t){let e=this.mouse;if(e[t]>0&&e.drag[t]<=0){e.drag[t]=1,e._isDragging=!0;let i=this.world.mouseSprite?.mouse;i&&(i.drag[t]=1,i._isDragging=!0)}},k=t._onmousemove;t._onmousemove=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),C.call(this,e),k.call(this,t)};const z=function(t){let e=this.mouse;e[t]>=e.holdThreshold?e[t]=-3:e[t]>1?e[t]=-1:e[t]=-2;let i=this.world.mouseSprite?.mouse;i&&(i.hover>1?(i[t]>=this.mouse.holdThreshold?i[t]=-3:i[t]>1?i[t]=-1:i[t]=-2,i.drag[t]>0&&(i.drag[t]=i[t])):(i[t]=0,i.drag[t]=0))},j=t._onmouseup;t._onmouseup=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),z.call(this,e),j.call(this,t)};const M=t._ontouchend;if(t._ontouchend=function(t){z.call(this,"left"),M.call(this,t)},delete this._Mouse,this._KeyBoard=class extends this.InputDevice{#e;constructor(){super(),this._default=" ",this.alt=0,this.arrowUp=0,this.arrowDown=0,this.arrowLeft=0,this.arrowRight=0,this.backspace=0,this.capsLock=0,this.control=0,this.enter=0,this.meta=0,this.shift=0,this.tab=0;let t=this._simpleKeyControls={arrowUp:"up",arrowDown:"down",arrowLeft:"left",arrowRight:"right"};t.w=t.W="up",t.s=t.S="down",t.a=t.A="left",t.d=t.D="right",t.i=t.I="up2",t.k=t.K="down2",t.j=t.J="left2",t.l=t.L="right2"}_ac(t){if(1!=t.length){if(!isNaN(t)){if(38==t)return"arrowUp";if(40==t)return"arrowDown";if(37==t)return"arrowLeft";if(39==t)return"arrowRight";if(t>=10)throw new Error("Use key names with the keyboard input functions, not keyCode numbers!");return t}t=t.replaceAll(/[ _-]/g,"")}if(1!=(t=t.toLowerCase()).length){if("arrowup"==t)return"arrowUp";if("arrowdown"==t)return"arrowDown";if("arrowleft"==t)return"arrowLeft";if("arrowright"==t)return"arrowRight";if("capslock"==t)return"capsLock"}return t}_pre(t){(!this[t]||this[t]<0)&&(this[t]=1)}_rel(t){this[t]>=this.holdThreshold?this[t]=-3:this[t]>1?this[t]=-1:this[t]=-2}get cmd(){return this.meta}get command(){return this.meta}get ctrl(){return this.control}get space(){return this[" "]}get spacebar(){return this[" "]}get opt(){return this.alt}get option(){return this.alt}get win(){return this.meta}get windows(){return this.meta}},this.kb=new this._KeyBoard,delete this._KeyBoard,this.keyboard=this.kb,navigator.keyboard){const t=navigator.keyboard;window==window.top?t.getLayoutMap().then((t=>{"w"!=t.get("KeyW")&&(this.p5play.standardizeKeyboard=!0)})):this.p5play.standardizeKeyboard=!0}else this.p5play.standardizeKeyboard=!0;function T(t){let e=t.code;return 4==e.length&&"Key"==e.slice(0,3)?e[3].toLowerCase():t.key}const L=t._onkeydown;t._onkeydown=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(t)),e.length>1)e=e[0].toLowerCase()+e.slice(1);else{let t=e.toLowerCase(),i=e.toUpperCase();t!=i&&(e!=i?this.kb._pre(i):this.kb._pre(t))}this.kb._pre(e);let i=this.kb._simpleKeyControls[e];i&&this.kb._pre(i),L.call(this,t)};const D=t._onkeyup;t._onkeyup=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(t)),e.length>1)e=e[0].toLowerCase()+e.slice(1);else{let t=e.toLowerCase(),i=e.toUpperCase();t!=i&&(e!=i?this.kb._rel(i):this.kb._rel(t))}this.kb._rel(e);let i=this.kb._simpleKeyControls[e];if(i&&this.kb._rel(i),t.shiftKey){let t=e.toLowerCase();this.kb[t]>0&&this.kb._rel(t)}D.call(this,t)},this._Contro=class extends this.InputDevice{constructor(t){super(),this._default="a",this.connected=!0;this._init(["a","b","x","y","l","r","lt","rt","select","start","lsb","rsb","up","down","left","right","leftTrigger","rightTrigger"]),this.leftStick={x:0,y:0,btn:0},this.rightStick={x:0,y:0,btn:0},this._btns={a:0,b:1,x:2,y:3,l:4,r:5,lt:6,rt:7,select:8,start:9,lsb:10,rsb:11,up:12,down:13,left:14,right:15},this._axes={leftStick:{x:0,y:1},rightStick:{x:2,y:3},leftTrigger:4,rightTrigger:5},t.id.includes("GuliKit")&&(this._btns.a=1,this._btns.b=0,this._btns.x=3,this._btns.y=2),this.gamepad=t,this.id=t.id}_ac(t){return"lb"==(t=t.toLowerCase())?t="l":"rb"==t?t="r":"leftstickbutton"==t?t="lsb":"rightstickbutton"==t&&(t="rsb"),t}_update(){if(!this.connected)return;if(this.gamepad=navigator.getGamepads()[this.gamepad.index],!this.gamepad?.connected)return;let t=this.gamepad;for(let e in this._btns){let i=this._btns[e];t.buttons[i].pressed?this[e]++:this[e]=this[e]>0?-1:0}return this.leftStick.x=t.axes[this._axes.leftStick.x],this.leftStick.y=t.axes[this._axes.leftStick.y],this.rightStick.x=t.axes[this._axes.rightStick.x],this.rightStick.y=t.axes[this._axes.rightStick.y],void 0!==t.axes[this._axes.leftTrigger]?(this.leftTrigger=t.axes[this._axes.leftTrigger],this.rightTrigger=t.axes[this._axes.rightTrigger]):(this.leftTrigger=t.buttons[this._btns.lt].value,this.rightTrigger=t.buttons[this._btns.rt].value),!0}get ls(){return this.leftStick}get rs(){return this.rightStick}get lb(){return this.l}get rb(){return this.r}get leftStickButton(){return this.lsb}get rightStickButton(){return this.rsb}},this._Contros=class extends Array{constructor(){super();let t=this;window.addEventListener("gamepadconnected",(e=>{t._onConnect(e.gamepad)})),window.addEventListener("gamepaddisconnected",(e=>{t._onDisconnect(e.gamepad)})),this.presses,this.pressing,this.pressed,this.holds,this.holding,this.held,this.released;let e=["presses","pressing","pressed","holds","holding","held","released"];for(let t of e)this[t]=e=>{if(this[0])return this[0][t](e)};this.a=0,this.b=0,this.x=0,this.y=0,this.l=0,this.r=0,this.lt=0,this.rt=0,this.select=0,this.start=0,this.lsb=0,this.rsb=0,this.up=0,this.down=0,this.left=0,this.right=0,this.leftTrigger=0,this.rightTrigger=0,this.lb=0,this.rb=0,this.leftStickButton=0,this.rightStickButton=0;let i=["connected","a","b","x","y","l","r","lt","rt","select","start","lsb","rsb","up","down","left","right","leftTrigger","rightTrigger","lb","rb","leftStickButton","rightStickButton"];for(let e of i)Object.defineProperty(this,e,{get:()=>t[0]?t[0][e]:0});this.leftStick,this.rightStick,i=["leftStick","rightStick"];for(let e of i){this[e]={};for(let i of["x","y"])Object.defineProperty(this[e],i,{get:()=>t[0]?t[0][e][i]:0})}if(!navigator?.getGamepads)return;let s=navigator.getGamepads();for(let t of s)t&&this._onConnect(t)}_onConnect(e){if(!e)return;for(let t=0;tthis.p5play._fps,this.p5play._fpsArr=[60],this.renderStats=(t,e)=>{let i=this.p5play._renderStats;void 0===i.show&&(1==this.allSprites.tileSize||this.allSprites.tileSize>16?i.fontSize=16:i.fontSize=10,i.gap=1.25*i.fontSize,console.warn("renderStats() uses inaccurate FPS approximations. Even if your game runs at a solid 60hz display rate, the fps calculations shown may be lower. The only way to get accurate results is to use your web browser's performance testing tools.")),i.x=t||10,i.y=e||20,i.show=!0}})),p5.prototype.registerMethod("pre",(function(){this.p5play._fps&&(this.p5play._preDrawFrameTime=performance.now()),this.p5play.spritesDrawn=0,this.mouse.x=(this.mouseX-this.world.hw)/this.camera.zoom+this.camera.x,this.mouse.y=(this.mouseY-this.world.hh)/this.camera.zoom+this.camera.y,this.camera.mouse.x=this.mouseX,this.camera.mouse.y=this.mouseY,this.contro._update()})),p5.prototype.registerMethod("post",(function(){this.p5play._inPostDraw=!0,this.allSprites.autoCull&&this.allSprites.cull(1e4),this.allSprites._autoDraw&&(this.camera.on(),this.allSprites.draw(),this.camera.off()),this.allSprites._autoDraw??=!0;let t=this.p5play._renderStats;if(t.show){if(1==this.frameCount||this.frameCount%60==0){let t,e=this.p5play._fpsArr.reduce(((t,e)=>t+e));e=Math.round(e/this.p5play._fpsArr.length),this.p5play._fpsAvg=e,this.p5play._fpsMin=Math.min(...this.p5play._fpsArr),this.p5play._fpsMax=Math.max(...this.p5play._fpsArr),this.p5play._fpsArr=[],t=e>55?this.color(30,255,30):e>25?this.color(255,100,30):this.color(255,30,30),this.p5play._statsColor=t}this.p5play._fpsArr.push(this.getFPS()),this.push(),this.fill(0,0,0,128),this.rect(t.x-5,t.y-t.fontSize,8.5*t.fontSize,4*t.gap+5),this.fill(this.p5play._statsColor),this.textSize(t.fontSize),this.textFont("monospace");let e=t.x,i=t.y;this.text("sprites: "+this.p5play.spritesDrawn,e,i),this.text("fps avg: "+this.p5play._fpsAvg,e,i+t.gap),this.text("fps min: "+this.p5play._fpsMin,e,i+2*t.gap),this.text("fps max: "+this.p5play._fpsMax,e,i+3*t.gap),this.pop(),t.show=!1}this.world.autoStep&&this.world.step(),this.world.autoStep??=!0,this.allSprites._autoUpdate&&this.allSprites.update(),this.allSprites._autoUpdate??=!0;for(let t of this.allSprites)t.autoDraw??=!0,t.autoUpdate??=!0;for(let t in this.kb)"holdThreshold"!=t&&(this.kb[t]<0?this.kb[t]=0:this.kb[t]>0&&this.kb[t]++);let e=this.mouse,i=this.world.mouseSprite?.mouse;for(let t of["left","center","right"])e[t]<0?e[t]=0:e[t]>0&&e[t]++,i&&(i[t]=e[t]);if(this.world.mouseTracking){let t=this.world.getSpritesAt(e.x,e.y);t.sort(((t,e)=>-1*(t._layer-e._layer)));let s=this.world.getSpritesAt(this.camera.mouse.x,this.camera.mouse.y,this.allSprites,!1);s.sort(((t,e)=>-1*(t._layer-e._layer))),t=t.concat(s);for(let e=0;e0?i.mouse.hover=-1:i.mouse.hover<0&&(i.mouse.hover=0):i.mouse.hover++}let r=this.world.mouseSprite;if(e.left<=0&&e.center<=0&&e.right<=0)r=null,this.world.mouseSprite=null;else for(let t of["left","center","right"])e.drag[t]<0?e.drag[t]=0:e.drag[t]>0&&e.drag[t]++,i&&(i.drag[t]=e.drag[t],i.x=r.x-e.x,i.y=r.y-e.y);for(let e of this.world.mouseSprites)if(!(i?._isDragging&&e==r||t.includes(e))){let t=e.mouse;t.hover=-1,t.left=t.center=t.right=0}this.world.mouseSprites=t}this.camera.off(),this.p5play._fps&&(this.p5play._postDrawFrameTime=performance.now(),this.p5play._fps=Math.round(1e3/(this.p5play._postDrawFrameTime-this.p5play._preDrawFrameTime))||1),this.p5play._inPostDraw=!1})); +p5.prototype.registerMethod("init",(function(){if(void 0===window.planck)throw"planck.js must be loaded before p5play";const t=this,e=planck,i=60;if(void 0===window._p5play_gtagged&&"undefined"==typeof process){let t=document.createElement("script");t.src="https://www.googletagmanager.com/gtag/js?id=G-EHXNCTSYLK",t.async=!0,document.head.append(t),window._p5play_gtagged=!0,t.onload=()=>{window.dataLayer??=[],window.gtag=function(){dataLayer.push(arguments)},gtag("js",new Date),gtag("config","G-EHXNCTSYLK"),gtag("event","p5play_v3_12")}}this.angleMode("degrees");const s=(t,s,r)=>new e.Vec2(t*r/i,s*r/i),r=(t,s,r)=>new e.Vec2(t/r*i,s/r*i),o=t=>Math.abs(t)<=e.Settings.linearSlop,h=t=>Math.abs(t-Math.round(t))<=e.Settings.linearSlop?Math.round(t):t,n={_collisions:["_collides","_colliding","_collided"],_overlappers:["_overlaps","_overlapping","_overlapped"]};this.p5play=new class{constructor(){this.os={},this.context="web",this.standardizeKeyboard=!1,this.sprites={},this.groups={},this.groupsCreated=0,this.spritesCreated=0,this.spritesDrawn=0,this._renderStats={},this.disableImages=!1,this.palettes=[]}},delete this.P5Play;const a=console.log;this.log=console.log,this.Sprite=class{constructor(s,r,o,n,a){this.p=t,this.idNum,this.watch,this.mod=[];let u,c,_=[...arguments];if(void 0!==_[0]&&_[0]instanceof this.p.Group&&(u=_[0],_=_.slice(1)),_.length||(this._noArgs=!0),void 0!==_[0]&&isNaN(_[0])&&("string"==typeof _[0]||_[0]instanceof this.p.SpriteAnimation||_[0]instanceof p5.Image)&&(c=_[0],_=_.slice(1)),1==_.length&&"number"==typeof _[0])throw new v("Sprite",0,[_[0]]);if(s=_[0],r=_[1],o=_[2],n=_[3],a=_[4],this._originMode="center",Array.isArray(s)&&(s=void 0,r=void 0,o=_[0],n=_[1],a=_[2]),Array.isArray(o)||"string"==typeof n){if(isNaN(o)||(o=Number(o)),"number"!=typeof o&&Array.isArray(o[0])&&(this._originMode="start"),void 0!==n){if(Array.isArray(n))throw new v("Sprite",1,[`[[${o}], [${n}]]`]);!function(t){let e=t.slice(0,2);return"d"==t||"s"==t||"k"==t||"n"==t||"dy"==e||"st"==e||"ki"==e||"no"==e}(n)?o=d(o,n):a=n,n=void 0}}else isNaN(o)&&(a=o,o=void 0);this.idNum=this.p.p5play.spritesCreated,this._uid=1e3+this.idNum,this.p.p5play.sprites[this._uid]=this,this.p.p5play.spritesCreated++,this.groups=[],this.animations=new this.p.SpriteAnimations,this.joints=[],this.joints.removeAll=()=>{for(let t of this.joints)t.remove()},this._removed=!1,this._life=2147483647,this._visible=!0,this._pixelPerfect=!1,this._aniChangeCount=0,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={},u??=this.p.allSprites,u.dynamic&&(a??="dynamic"),u.kinematic&&(a??="kinematic"),u.static&&(a??="static"),a??=u.collider,this._shape=u.shape,this.tileSize=u.tileSize||1;let f=this;if(this._position={x:0,y:0},this._pos=t.createVector.call(t),Object.defineProperty(this._pos,"x",{get(){if(!f.body)return f._position.x;let t=f.body.getPosition().x/f.tileSize*i;return h(t)},set(t){if(f.body){let s=new e.Vec2(t*f.tileSize/i,f.body.getPosition().y);f.body.setPosition(s)}f._position.x=t}}),Object.defineProperty(this._pos,"y",{get(){if(!f.body)return f._position.y;let t=f.body.getPosition().y/f.tileSize*i;return h(t)},set(t){if(f.body){let s=new e.Vec2(f.body.getPosition().x,t*f.tileSize/i);f.body.setPosition(s)}f._position.y=t}}),this._velocity={x:0,y:0},this._vel=t.createVector.call(t),Object.defineProperties(this._vel,{x:{get(){let t;return t=f.body?f.body.getLinearVelocity().x:f._velocity.x,h(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new e.Vec2(t,f.body.getLinearVelocity().y)):f._velocity.x=t}},y:{get(){let t;return t=f.body?f.body.getLinearVelocity().y:f._velocity.y,h(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new e.Vec2(f.body.getLinearVelocity().x,t)):f._velocity.y=t}}}),this._mirror={_x:1,_y:1,get x(){return this._x<0},set x(t){f.watch&&(f.mod[22]=!0),this._x=t?-1:1},get y(){return this._y<0},set y(t){f.watch&&(f.mod[22]=!0),this._y=t?-1:1}},this._heading="right",this._layer=u._layer,this._layer??=this.p.allSprites._getTopLayer()+1,a??=u.collider,a&&"string"==typeof a||(a="dynamic"),this.collider=a,s??=u.x,void 0===s&&(s=this.p.width/this.p.allSprites.tileSize/2,this._vertexMode=!0),r??=u.y,void 0===r&&(r=this.p.height/this.p.allSprites.tileSize/2),null==o&&(o=u.w||u.width||u.d||u.diameter,n??=u.h||u.height),"function"==typeof s&&(s=s(u.length)),"function"==typeof r&&(r=r(u.length)),"function"==typeof o&&(o=o(u.length)),"function"==typeof n&&(n=n(u.length)),this.x=s,this.y=r,!u._isAllSpritesGroup&&!c)for(let t in u.animations){c=t;break}for(let t=u;t;t=this.p.p5play.groups[t.parent])this.groups.push(t);if(this.groups.reverse(),c){c instanceof p5.Image?this.addAni(c):("string"==typeof c?this._changeAni(c):this._ani=c.clone(),this._ani.name=c.name);let t=this.tileSize;o||1==this._ani.w&&1==this._ani.h||(o=this._ani.w/t,n||"circle"==this.shape||(n=this._ani.h/t))}if(this.groups=[],this.mouse=new this.p._SpriteMouse,"none"!=this.collider)this._vertexMode?this.addCollider(o,n):this.addCollider(0,0,o,n);else{if(this.w=o||(this.tileSize>1?1:50),this.h=n||this.w,Array.isArray(o))throw new Error('Cannot set the collider type of a sprite with a polygon or chain shape to "none". Try having the sprite overlap with other sprites instead.');this._shape=void 0!==o&&void 0===n?"circle":"box"}u._isAllSpritesGroup||this.p.allSprites.push(this),u.push(this),this._scale=new l,Object.defineProperty(this._scale,"x",{get(){return this._x},set(t){if(t==this._x)return;f.watch&&(f.mod[28]=!0);let e=t/this._x;f._w*=e,f._hw*=e,f._resizeColliders({x:e,y:1}),this._x=t,this._avg=.5*(this._x+this._y)}}),Object.defineProperty(this._scale,"y",{get(){return this._y},set(t){if(t==this._y)return;f.watch&&(f.mod[28]=!0);let e=t/this._y;f._h&&(this._h*=e,this._hh*=e),f._resizeColliders({x:1,y:e}),this._y=t,this._avg=.5*(this._x+this._y)}}),this._offset={_x:0,_y:0,get x(){return this._x},set x(t){t!=this._x&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(t-this._x,0))},get y(){return this._y},set y(t){t!=this._y&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(0,t-this._y))}},this._angle=0,this._rotationSpeed=0,this._bearing=0,this.prevPos={x:s,y:r},this.prevRotation=0,this._dest={x:s,y:r},this._destIdx=0,this.drag=0,this.debug=!1,this._shift={};let g=u.vel.x||0,y=u.vel.y||0;"function"==typeof g&&(g=g(u.length-1)),"function"==typeof y&&(y=y(u.length-1)),this.vel.x=g,this.vel.y=y;let m=["ani","collider","vel","x","y","w","h","d","diameter","dynamic","height","kinematic","speed","static","width"];for(let t of this.p.Sprite.propsAll){if(m.includes(t))continue;let e=u[t];void 0!==e&&("function"==typeof e&&p(e)&&(e=e(u.length-1)),this[t]="object"==typeof e?Object.assign({},e):e)}m=["add","animation","animations","autoCull","contains","GroupSprite","Group","idNum","length","mod","mouse","p","parent","Sprite","Subgroup","subgroups","velocity"];for(let t=0;t1?1:50,h??=r),"box"!=a&&"circle"!=a||(l=s(r-.08,h-.08,this.tileSize)),"box"==a)p=e.Box(l.x/2,l.y/2,s(t,i,this.tileSize),0);else if("circle"==a)p=e.Circle(s(t,i,this.tileSize),l.x/2);else if(n){let c,_,f=[{x:0,y:0}],g={x:0,y:0},y={x:0,y:0},m={x:0,y:0},w=Array.isArray(n[0]);function x(){g.xm.x&&(m.x=g.x),g.y>m.y&&(m.y=g.y)}if(w){this._vertexMode&&(c=n[0][0],_=n[0][1],this.body?(c=this.x-this._relativeOrigin.x,_=this.y-this._relativeOrigin.y,f.pop()):(this.x=c,this.y=_));for(let b=0;b0?1:-1;S=Math.abs(S);let C=0;for(let k=0;ke.Settings.maxPolygonVertices||"chain"==this._shape)&&(a="chain"),"polygon"==a?p=e.Polygon(f):"chain"==a&&(p=e.Chain(f,!1))}return this._shape||(this._shape=a),this._w=r,this._hw=.5*r,"circle"==this._shape?this._diameter=r:(this._h=h,this._hh=.5*h),p}removeColliders(){this._collides={},this._colliding={},this._collided={},this._removeFixtures(!1)}removeSensors(){this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._removeFixtures(!0)}_removeFixtures(t){let e;for(let i=this.fixtureList;i;i=i.getNext())if(void 0===t||i.m_isSensor==t){let t=i.m_next;i.destroyProxies(this.p.world.m_broadPhase),e?e.m_next=t:this.body.m_fixtureList=t}else e=i}_offsetCenterBy(t,e){if(!t&&!e)return;if(this._offset._x+=t,this._offset._y+=e,!this.body)return;let i=s(t,e,this.tileSize);for(let t=this.body.m_fixtureList;t;t=t.m_next){let e=t.m_shape;if("circle"!=e.m_type){let t=e.m_vertices;for(let e of t)e.x+=i.x,e.y+=i.y}else e.m_p.x+=i.x,e.m_p.y+=i.y}}_cloneBodyProps(){let t={},e=["bounciness","density","drag","friction","heading","isSuperFast","rotation","rotationDrag","rotationLock","rotationSpeed","scale","vel","x","y"];this._massUndef&&this._dimensionsUndef||e.push("mass");for(let i of e)"object"==typeof this[i]?t[i]=Object.assign({},this[i]):t[i]=this[i];return t}get animation(){return this._ani}set animation(t){this.changeAni(t)}get ani(){return this._ani}set ani(t){this.changeAni(t)}get anis(){return this.animations}get autoDraw(){return this._autoDraw}set autoDraw(t){this.watch&&(this.mod[6]=!0),this._autoDraw=t}get allowSleeping(){return this.body?.isSleepingAllowed()}set allowSleeping(t){this.watch&&(this.mod[7]=!0),this.body&&this.body.setSleepingAllowed(t)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){this.watch&&(this.mod[8]=!0),this._autoUpdate=t}get bounciness(){if(this.fixture)return this.fixture.getRestitution()}set bounciness(t){this.watch&&(this.mod[9]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setRestitution(t)}get centerOfMass(){let t=this.body.getWorldCenter(),e=r(t.x,t.y,this.tileSize);return this.p.createVector(e.x,e.y)}get collider(){return this._collider}set collider(t){let e=(t=t.toLowerCase())[0];if("d"==e&&(t="dynamic"),"s"==e&&(t="static"),"k"==e&&(t="kinematic"),"n"==e&&(t="none"),t==this._collider)return;if(this.__collider=["d","s","k","n"].indexOf(e),void 0===this._collider)return void(this._collider=t);if("none"==t&&("chain"==this._shape||"polygon"==this._shape))throw new Error('Cannot set the collider type of a polygon or chain collider to "none". Try having the sprite overlap with other sprites instead.');this.joints.length&&(this.joints.removeAll(),console.warn("Changing the collider type of a sprite that has joints will remove all its joints.")),this.watch&&(this.mod[10]=!0);let i=this._collider;this._collider=t,void 0!==i&&this._reset()}_reset(){let t,e=this._cloneBodyProps();"chain"!=this._shape&&"polygon"!=this._shape||(t=this._getVertices(!0),this._vertexMode=!0),this.body&&(this.p.world.destroyBody(this.body),this.body=void 0),"none"!=this._collider&&(t?this.addCollider(0,0,t):this.addCollider(),this._hasSensors&&this.addDefaultSensors());for(let t in e)void 0!==e[t]&&(this[t]=e[t]);let i=this._offset._x,s=this._offset._y;this._offset._x=0,this._offset._y=0,this._offsetCenterBy(i,s)}_parseColor(t){if(t instanceof p5.Color)return t;if("object"!=typeof t)return"string"==typeof t&&1==t.length?this.p.colorPal(t):this.p.color(t);if(t.levels)return this.p.color(...t.levels);if(void 0!==t._r)return this.p.color(t._r,t._g,t._b,255*t._a);if(void 0!==t._h)return this.p.color(t._h,t._s,t._v,255*t._a);throw new Error("Invalid color")}get color(){return this._color}set color(t){this.watch&&(this.mod[11]=!0),this._color=this._parseColor(t)}get colour(){return this._color}set colour(t){this.color=t}get fill(){return this._color}set fill(t){this.color=t}get fillColor(){return this._color}set fillColor(t){this.color=t}get stroke(){return this._stroke}set stroke(t){this.watch&&(this.mod[31]=!0),this._stroke=this._parseColor(t)}get strokeColor(){return this._stroke}set strokeColor(t){this.stroke=t}get strokeWeight(){return this._strokeWeight}set strokeWeight(t){this.watch&&(this.mod[32]=!0),this._strokeWeight=t}get textColor(){return this._textColor}set textColor(t){this.watch&&(this.mod[34]=!0),this._textColor=this._parseColor(t)}get bearing(){return this._bearing}set bearing(t){this.watch&&(this.mod[39]=!0),this._bearing=t}get debug(){return this._debug}set debug(t){this.watch&&(this.mod[12]=!0),this._debug=t}get density(){if(this.fixture)return this.fixture.getDensity()}set density(t){this.watch&&(this.mod[13]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setDensity(t)}_getDirectionAngle(t){t=t.toLowerCase().replaceAll(/[ _-]/g,"");let e={up:-90,down:90,left:180,right:0,upright:-45,rightup:-45,upleft:-135,leftup:-135,downright:45,rightdown:45,downleft:135,leftdown:135,forward:this.rotation,backward:this.rotation+180}[t];return"radians"==this.p._angleMode&&(e=this.p.radians(e)),e}get direction(){return 0!==this.vel.x||0!==this.vel.y?this.p.atan2(this.vel.y,this.vel.x):void 0===this._direction?this.rotation:this._direction}set direction(t){this.watch&&(this.mod[14]=!0),"string"==typeof t&&(this._heading=t,t=this._getDirectionAngle(t)),this._direction=t;let e=this.speed;this.vel.x=this.p.cos(t)*e,this.vel.y=this.p.sin(t)*e}get drag(){return this.body?.getLinearDamping()}set drag(t){this.watch&&(this.mod[15]=!0),this.body&&this.body.setLinearDamping(t)}get draw(){return this._display}set draw(t){this._draw=t}get dynamic(){return this.body?.isDynamic()}set dynamic(t){this.collider=t?"dynamic":"kinematic"}get fixture(){return this.fixtureList}get fixtureList(){return this.body?this.body.m_fixtureList:null}get friction(){if(this.fixture)return this.fixture.getFriction()}set friction(t){this.watch&&(this.mod[16]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setFriction(t)}get heading(){return this._heading}set heading(t){this.direction=t}get img(){return this._ani?.frameImage}set img(t){this.changeAni(t)}get image(){return this._ani?.frameImage}set image(t){this.changeAni(t)}get isMoving(){return 0!=this.vel.x||0!=this.vel.y}get isSuperFast(){return this.body?.isBullet()}set isSuperFast(t){this.watch&&(this.mod[18]=!0),this.body&&this.body.setBullet(t)}get kinematic(){return this.body?.isKinematic()}set kinematic(t){this.collider=t?"kinematic":"dynamic"}get layer(){return this._layer}set layer(t){this.watch&&(this.mod[19]=!0),this._layer=t}get life(){return this._life}set life(t){this.watch&&(this.mod[20]=!0),this._life=t}get mass(){return this.body?.getMass()}set mass(t){if(!this.body)return;this.watch&&(this.mod[21]=!0);let e=this.massData;e.mass=t>0?t:1e-8,this.body.setMassData(e),delete this._massUndef}get massData(){const t={I:0,center:new e.Vec2(0,0),mass:0};return this.body.getMassData(t),t.center=r(t.center.x,t.center.y,this.tileSize),t}resetMass(){this.body&&(this.watch&&(this.mod[21]=!0),this.body.resetMassData(),delete this._massUndef)}get mirror(){return this._mirror}set mirror(t){this.watch&&(this.mod[22]=!0),void 0!==t.x&&(this._mirror.x=t.x),void 0!==t.y&&(this._mirror.y=t.y)}get offset(){return this._offset}set offset(t){t.x??=this._offset._x,t.y??=this._offset._y,t.x==this._offset._x&&t.y==this._offset._y||(this.watch&&(this.mod[23]=!0),this._offsetCenterBy(t.x-this._offset._x,t.y-this._offset._y))}get previousPosition(){return this.prevPos}set previousPosition(t){this.prevPos=t}get previousRotation(){return this.prevRotation}set previousRotation(t){this.prevRotation=t}get pixelPerfect(){return this._pixelPerfect}set pixelPerfect(t){this.watch&&(this.mod[24]=!0),this._pixelPerfect=t}get rotation(){if(!this.body)return this._angle||0;let t=this.body.getAngle();return"degrees"===this.p._angleMode?this.p.degrees(t):t}set rotation(t){this.body?("degrees"===this.p._angleMode&&(t=this.p.radians(t)),this.body.setAngle(t)):this._angle=t}get rotationDrag(){return this.body?.getAngularDamping()}set rotationDrag(t){this.body&&(this.watch&&(this.mod[26]=!0),this.body.setAngularDamping(t))}get rotationLock(){return this.body?.isFixedRotation()}set rotationLock(t){this.body&&(this.watch&&(this.mod[27]=!0),this.body.setFixedRotation(t))}get rotationSpeed(){return this.body?this.body.getAngularVelocity():this._rotationSpeed}set rotationSpeed(t){this.body?this.body.setAngularVelocity(t):this._rotationSpeed=t}get scale(){return this._scale}set scale(t){if(t<=0&&(t=.01),"number"==typeof t?t={x:t,y:t}:(t.x??=this._scale._x,t.y??=this._scale._y),t.x==this._scale._x&&t.y==this._scale._y)return;this.watch&&(this.mod[28]=!0);let e={x:t.x/this._scale._x,y:t.y/this._scale._y};this._w*=e.x,this._hw*=e.x,this._h&&(this._h*=e.y,this._hh*=e.y),this._resizeColliders(e),this._scale._x=t.x,this._scale._y=t.y,this._scale._avg=t.x}get sleeping(){if(this.body)return!this.body.isAwake()}set sleeping(t){this.body&&(this.watch&&(this.mod[30]=!0),this.body.setAwake(!t))}get speed(){return this.p.createVector(this.vel.x,this.vel.y).mag()}set speed(t){let e=this.direction;this.vel.x=this.p.cos(e)*t,this.vel.y=this.p.sin(e)*t}get static(){return this.body?.isStatic()}set static(t){this.collider=t?"static":"dynamic"}get removed(){return this._removed}set removed(t){t&&!this._removed&&(this.watch&&(this.mod[25]=!0),this._removed=!0,this._remove())}get vertices(){return this._getVertices()}_getVertices(t){let e=this.fixture;for(;e.m_next&&!e.m_isSensor;)e=e.m_next;let s=e.getShape(),r=[...s.m_vertices];"polygon"==s.m_type&&r.unshift(r.at(-1));let o=this.x,n=this.y;for(let e=0;e=1e3?this.p.p5play.sprites[r]:this.p.p5play.groups[r];let o=i[s][r]+1;if(this[s][r]=o,t instanceof this.p.Group&&(t[s][i._uid]=o),t&&0!=o){if(!(t instanceof this.p.Group)){e=[],1!=o&&-2!=o||e.push(n[s][0]),-1!=o&&e.push(n[s][1]),-1!=o&&-2!=o||e.push(n[s][2]);for(let s of e){let e=this.p.world._findContact(s,i,t,!0);e&&e(i,t,o)}}}else delete i[s][r],t instanceof this.p.Group&&delete t[s][i._uid]}this.removed&&0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}_draw(){if(void 0!==this.strokeWeight&&this.p.strokeWeight(this.strokeWeight),this._ani?.draw&&"colliders"!=this.debug&&this._ani.draw(this._offset._x,this._offset._y,0,this._scale._x,this._scale._y),!this._ani||this.debug||this.p.p5play.disableImages)if(this.debug&&"colliders"!=this.debug&&(this.p.noFill(),this.p.stroke(0,255,0),this.p.line(0,-2,0,2),this.p.line(-2,0,2,0)),3!=this.__collider){"chain"==this._shape?this.p.stroke(this.stroke||this.color):this._stroke&&this.p.stroke(this._stroke);for(let t=this.fixtureList;t;t=t.getNext())t.m_isSensor&&!this.debug||this._drawFixture(t)}else this.p.stroke(this._stroke||120),"box"==this._shape?this.p.rect(this._offset._x,this._offset._y,this.w*this.tileSize,this.h*this.tileSize):"circle"==this._shape&&this.p.circle(this._offset._x,this._offset._y,this.d*this.tileSize);void 0!==this.text&&(this.p.textAlign(this.p.CENTER,this.p.CENTER),this.p.fill(this.textColor),this.p.textSize(this.textSize*this.tileSize),this.p.text(this.text,0,0))}_display(){let t=.5*this.p.width-this.p.world._origin.x+this.x*this.tileSize,e=.5*this.p.height-this.p.world._origin.y+this.y*this.tileSize,i=Math.max(this._w,this._h);if("chain"!=this.shape&&this.p.camera.active&&(t+ithis.p.camera.bound.max.x||e+ithis.p.camera.bound.max.y))this._visible=null;else{this._visible=!0,this.p.p5play.spritesDrawn++,this._pixelPerfect?(t=this._w%2==0?Math.round(t):Math.round(t-.5)+.5,e=this._h%2==0?Math.round(e):Math.round(e-.5)+.5):(t=h(t),e=h(e));for(let t of this.joints)t.visible?this._uid==t.spriteA._uid?(!t.spriteB._visible||this.layer<=t.spriteB.layer)&&t._display():(!t.spriteA._visible||this.layer1?(r=Math.round(r),o=Math.round(o)):e%90==0&&(r=h(r),o=h(o)),this.moveTo(r,o,i)}moveTo(e,i,s){if("number"!=typeof e){let t=e;if(t==this.p.mouse&&!this.p.mouse.active)return;if(!t||void 0===t.x||void 0===t.y)throw"sprite.moveTo ERROR: destination not defined.";s=i,i=t.y,e=t.x}if(this._dest.x=this.x,this._dest.y=this.y,e==this.x?e=!1:(this._dest.x=e,e=!0),i==this.y?i=!1:(this._dest.y=i,i=!0),this._destIdx++,!e&&!i)return Promise.resolve(!0);if(this.speed&&(s??=this.speed),this.tileSize>1&&(s??=.1),s??=1,s<=0)return console.warn("sprite.move: speed should be a positive number"),Promise.resolve(!1);let r=this._dest.y-this.y,o=this._dest.x-this.x,h=s/Math.sqrt(r*r+o*o);this.vel.x=o*h,this.vel.y=r*h;let n=this.direction,a=n-.1,l=n+.1,p=s+.01,d=this._destIdx,u=Math.max(this.p.world.velocityThreshold,.25*p)/this.tileSize;return(async()=>{let s=p+p,r=p+p;do{if(d!=this._destIdx)return!1;await t.delay();let e=this.direction;if(e<=a||e>=l||Math.abs(this.vel.x)<=u&&Math.abs(this.vel.y)<=u)return!1;s=Math.abs(this.x-this._dest.x),r=Math.abs(this.y-this._dest.y)}while(e&&s>p||i&&r>p);return s2&&(i=o[0],s=o[1],e=o[2],r=o[3]),void 0!==i?t=this.angleToFace(i,s,r):t-=this.rotation,e??=.1,this.rotationSpeed=t*e}angleTo(t,e){if("object"==typeof t){let i=t;if(i==this.p.mouse&&!this.p.mouse.active)return 0;if(void 0===i.x||void 0===i.y)return console.error("sprite.angleTo ERROR: rotation destination not defined, object given with no x or y properties"),0;e=i.y,t=i.x}return this.p.atan2(e-this.y,t-this.x)}angleToFace(t,e,i){if("object"==typeof t&&(i=e,e=t.y,t=t.x),Math.abs(t-this.x)<.01&&Math.abs(e-this.y)<.01)return 0;let s=this.angleTo(t,e);i??=0,s+=i;let r=s-this.rotation%360,o=360-Math.abs(r);return o*=r<0?1:-1,Math.abs(r)2&&(i=o[0],s=o[1],e=o[2],r=o[3]),void 0!==i)t=this.angleToFace(i,s,r);else{if(t==this.rotation)return;t-=this.rotation}return this.rotate(t,e)}rotate(e,i){if(1==this.__collider)throw new v(0);if(isNaN(e))throw new v(1,[e]);if(0==e)return;let s=Math.abs(e);i??=1,i>s&&(i=s);let r=this.rotation+e,o=e>0;this.rotationSpeed=i*(o?1:-1);let h=Math.floor(s/i)-1;this._rotateIdx??=0,this._rotateIdx++;let n=this._rotateIdx;return(async()=>{if(h>1){let e=Math.abs(this.rotationSpeed)+.01;do{if(this._rotateIdx!=n)return!1;if(await t.delay(),o&&this.rotationSpeed<.01||!o&&this.rotationSpeed>-.01)return!1}while((o&&r>this.rotation||!o&&r.01&&(this.rotationSpeed=r-this.rotation,await t.delay())}else await t.delay();return this._rotateIdx==n&&(this.rotationSpeed=0,this.rotation=r,!0)})()}async changeAni(t){if(this.p.p5play.disableImages)return;if(arguments.length>1)t=[...arguments];else if(t instanceof this.p.SpriteAnimation){if(t==this._ani)return;t=[t]}else if(!Array.isArray(t)){if(t==this._ani?.name)return;t=[t]}let e,i;this._aniChangeCount++;for(let s=0;s1&&("!"==r.name[0]&&(r.name=r.name.slice(1),r.start=-1,r.end=0),"<"!=r.name[0]&&">"!=r.name[0]||(r.name=r.name.slice(1),r.flipX=!0),"^"==r.name[0]&&(r.name=r.name.slice(1),r.flipY=!0),"**"==r.name&&(e=!0,t=t.slice(0,-1)),";;"==r.name&&(i=!0,t=t.slice(0,-1)))}let s=this._aniChangeCount;do{for(let e=0;e1&&(i.start=0),await this._playSequencedAni(i)}}while(e&&s==this._aniChangeCount);1!=t.length&&i&&this._ani.stop()}_playSequencedAni(t){return new Promise((e=>{let{name:i,start:s,end:r,flipX:o,flipY:h}=t;this._changeAni(i),o&&(this._ani.scale.x=-this._ani.scale.x),h&&(this._ani.scale.y=-this._ani.scale.y),s<0&&(s=this._ani.length+s),void 0!==s&&(this._ani.frame=s),void 0!==r?this._ani.goToFrame(r):this._ani.frame==this._ani.lastFrame&&e(),this._ani._onComplete=this._ani._onChange=()=>{o&&(this._ani.scale.x=-this._ani.scale.x),h&&(this._ani.scale.y=-this._ani.scale.y),this._ani._onComplete=this._ani._onChange=null,e()}}))}changeAnimation(){return this.changeAni(...arguments)}_changeAni(t){this._ani?._onChange&&this._ani._onChange(),this._ani?.onChange&&this._ani.onChange();let e=this.animations[t];if(!e)for(let i=this.groups.length-1;i>=0;i--){if(e=this.groups[i].animations[t],e){e=e.clone();break}}if(!e)throw this.p.noLoop(),new v("Sprite.changeAnimation",[t]);this._ani=e,this._ani.name=t,this.resetAnimationsOnChange&&(this._ani.frame=0)}remove(){this.removed=!0}_remove(){this.body&&this.p.world.destroyBody(this.body),this.body=null;for(let t of this.groups)t.remove(this);0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}toString(){return"s"+this.idNum}_ensureCollide(t,e){if(!t)throw new v("Sprite.collide",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.collide",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.collide",1,[e]);if(!1!==this._hasOverlap[t._uid]&&(this._hasOverlap[t._uid]=!1),!1!==t._hasOverlap[this._uid]&&(t._hasOverlap[this._uid]=!1,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!1}collide(t,e){return this.collides(t,e)}collides(t,e){return this._ensureCollide(t,e),this._collides[t._uid]=e||!0,1==this._collisions[t._uid]}colliding(t,e){this._ensureCollide(t,e),this._colliding[t._uid]=e||!0;let i=this._collisions[t._uid];return i>0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){if(t instanceof this.p.Group)for(let e of t)this._removeContactsWith(e);else this.__removeContactsWith(t)}__removeContactsWith(t){if(this.body)for(let e=this.body.getContactList();e;e=e.next){let i=e.contact;i.m_fixtureA.m_body.sprite._uid!=t._uid&&i.m_fixtureB.m_body.sprite._uid!=t._uid||this.p.world.destroyContact(i)}}_ensureOverlap(t,e){if(!t)throw new v("Sprite.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.overlap",1,[e]);if(this._hasSensors||this.addDefaultSensors(),!t._hasSensors)if(t instanceof this.p.Sprite)t.addDefaultSensors();else{for(let e of t)e._hasSensors||e.addDefaultSensors();t._hasSensors=!0}if(1!=this._hasOverlap[t._uid]&&(this._removeContactsWith(t),this._hasOverlap[t._uid]=!0),1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}_sortFixtures(){let t=null,e=null;for(let i=this.fixtureList;i;i=i.getNext())i.m_isSensor?e?e.m_next=i:e=i:t?t.m_next=i:t=i;e&&(e.m_next=null),t&&(t.m_next=e),this.body.m_fixtureList=t||e}addDefaultSensors(){let t;if(this.body){for(let e=this.fixtureList;e;e=e.getNext())e.m_isSensor||(t=e.m_shape,this.body.createFixture({shape:t,isSensor:!0}));this._sortFixtures()}else this.addSensor();this._hasSensors=!0}},this.Sprite.propTypes={x:"Float64",y:"Float64",vel:"Vec2",rotation:"number",rotationSpeed:"number",ani:"string",autoDraw:"boolean",allowSleeping:"boolean",autoUpdate:"boolean",bounciness:"number",collider:"Uint8",color:"color",debug:"boolean",density:"number",direction:"number",drag:"number",friction:"number",h:"number",isSuperFast:"boolean",layer:"number",life:"Int32",mass:"number",mirror:"Vec2_boolean",offset:"Vec2",pixelPerfect:"boolean",removed:"boolean",rotationDrag:"number",rotationLock:"boolean",scale:"Vec2",shape:"Uint8",sleeping:"boolean",stroke:"color",strokeWeight:"number",text:"string",textColor:"color",tile:"string",tileSize:"number",visible:"boolean",w:"number",bearing:"number"},this.Sprite.props=Object.keys(this.Sprite.propTypes),this.Sprite.propsAll=this.Sprite.props.concat(["d","diameter","dynamic","fill","height","heading","kinematic","resetAnimationsOnChange","speed","static","width"]),this.Sprite.colliderTypes=["d","s","k","n"],this.Sprite.shapeTypes=["box","circle","chain","polygon"],this.Turtle=function(e){if(t.allSprites.tileSize>1)throw new Error("Turtle can't be used when allSprites.tileSize is greater than 1.");e??=25;let i=new t.Sprite(e,e,[[e,.4*e],[-e,.4*e],[0,.8*-e]]);i.color="green",i._isTurtleSprite=!0,i._prevPos={x:i.x,y:i.y};let s=i.move;return i.move=async function(){this._prevPos.x=this.x,this._prevPos.y=this.y,await s.call(this,...arguments)},i},this.SpriteAnimation=class extends Array{constructor(){super(),this.p=t;let e,i=[...arguments];if(this.name="default",(i[0]instanceof this.p.Sprite||i[0]instanceof this.p.Group)&&(e=i[0],i=i.slice(1),this._addedToSpriteOrGroup=!0),e??=this.p.allSprites,"string"!=typeof i[0]||1!=i[0].length&&i[0].includes(".")||(this.name=i[0],i=i.slice(1)),this.frame=0,this._cycles=0,this.targetFrame=-1,this.offset={x:e.anis.offset.x||0,y:e.anis.offset.y||0},this._frameDelay=e.anis.frameDelay||4,this.demoMode=e.anis.demoMode||!1,this.playing=!0,this.visible=!0,this.looping=e.anis.looping,this.looping??=!0,this.endOnFirstFrame=!1,this.frameChanged=!1,this.onComplete=this.onChange=null,this._onComplete=this._onChange=null,this.rotation=e.anis.rotation||0,this._scale=new l,0!=i.length&&"number"!=typeof i[0])if(e.animations[this.name]=this,e._ani=this,Array.isArray(i[0])&&"string"==typeof i[0][0]&&(i=[...i[0]]),2!=i.length||"string"!=typeof i[0]||"string"!=typeof i[1]&&"number"!=typeof i[1])if("string"==typeof i[i.length-1]||i[i.length-1]instanceof p5.Image)for(let s=0;s=3)throw new v("SpriteAnimation",1);o=i[0],r=i[1]}else r=i[0];let h=this;if(o instanceof p5.Image&&1!=o.width&&1!=o.height)this.spriteSheet=o,n();else{let a;a="string"==typeof o?o:o.url,this.spriteSheet=this.p.loadImage(a,(()=>{n()}))}function n(){if(Array.isArray(r)||Array.isArray(r.frames)){if("number"!=typeof r[0]){let t=r;if(Array.isArray(r.frames)){t=r.frames,delete r.frames;for(let e=0;e=h.spriteSheet.width&&(u=0,c+=i,c>=h.spriteSheet.height&&(c=0))}}else{let p,d,u=i[0];if(isNaN(i[1])?p=i[1]:d=Number(i[1]),".png"!=u.slice(-4)||p&&".png"!=p.slice(-4))throw new v("SpriteAnimation",0,[u]);let c=0,_=0;for(let y=u.length-5;y>=0&&!isNaN(u.charAt(y));y--)c++;if(p)for(let m=p.length-5;m>=0&&!isNaN(p.charAt(m));m--)_++;let f,g=u.slice(0,-4-c);if(p&&(f=p.slice(0,-4-_)),p&&g!=f)this.push(this.p.loadImage(u)),this.push(this.p.loadImage(p));else{let w,x=parseInt(u.slice(-4-c,-4),10);if(d??=parseInt(p.slice(-4-_,-4),10),dthis.frame&&-1!==this.targetFrame?this.frame++:this.targetFrame=this.lastFrame?this.frame=0:this.frame++:this.frame{this._onComplete=()=>{this._onComplete=null,t()}}))}pause(t){this.playing=!1,t&&(this.frame=t)}stop(t){this.playing=!1,t&&(this.frame=t)}rewind(){return this.looping=!1,this.goToFrame(0)}loop(){this.looping=!0,this.playing=!0}noLoop(){this.looping=!1}nextFrame(){this.frame0?this.frame=this.frame-1:this.looping&&(this.frame=this.length-1),this.targetFrame=-1,this.playing=!1}goToFrame(t){if(!(t<0||t>=this.length))return this.targetFrame=t,this.targetFrame!==this.frame&&(this.playing=!0),new Promise((t=>{this._onComplete=()=>{this._onComplete=null,t()}}))}get lastFrame(){return this.length-1}get frameImage(){let t=this[this.frame];if(t instanceof p5.Image)return t;let{x:e,y:i,w:s,h:r}=t,o=createGraphics(s,r);return o.image(this.spriteSheet,this.offset.x,this.offset.y,s,r,e,i,s,r),o}get w(){return this.width}get width(){return this[this.frame]instanceof p5.Image?this[this.frame].width:this[this.frame]?this[this.frame].w:1}get h(){return this.height}get height(){return this[this.frame]instanceof p5.Image?this[this.frame].height:this[this.frame]?this[this.frame].h:1}get frames(){let t=[];for(let e=0;ee.#t[t],set(i){e.#t[t]=i;for(let s in e){let r=e[s];r instanceof SpriteAnimation&&(r[t]=i)}}});for(let t of s){this.#t[t]={_x:0,_y:0};for(let i of["x","y"])Object.defineProperty(this.#t[t],i,{get:()=>e.#t[t]["_"+i],set(s){e.#t[t]["_"+i]=s;for(let r in e){let o=e[r];o instanceof SpriteAnimation&&(o[t][i]=s)}}})}}},this.Group=class extends Array{constructor(...e){let i;if(e[0]instanceof t.Group&&(i=e[0],e=e.slice(1)),super(...e),this.p=t,"number"==typeof e[0])return;for(let t of this)if(!(t instanceof this.p.Sprite))throw new Error("A group can only contain sprites");if(this.x,this.y,this.vel,this.rotation,this.rotationSpeed,this.autoDraw,this.allowSleeping,this.autoUpdate,this.bounciness,this.collider,this.color,this.debug,this.density,this.direction,this.drag,this.friction,this.h,this.isSuperFast,this.layer,this.life,this.mass,this.mirror,this.offset,this.pixelPerfect,this.removed,this.rotationDrag,this.rotationLock,this.scale,this.shape,this.sleeping,this.stroke,this.strokeWeight,this.text,this.textColor,this.tile,this.tileSize,this.visible,this.w,this.bearing,this.d,this.diameter,this.dynamic,this.height,this.heading,this.kinematic,this.resetAnimationsOnChange,this.speed,this.static,this.width,this.idNum=this.p.p5play.groupsCreated,this._uid=this.idNum,this.p.p5play.groups[this._uid]=this,this.p.p5play.groupsCreated++,this.p.allSprites||(this._isAllSpritesGroup=!0),this.subgroups=[],i instanceof this.p.Group){i.subgroups.push(this);let t=i;do{t=this.p.p5play.groups[t.parent],t.subgroups.push(this)}while(!t._isAllSpritesGroup);this.parent=i._uid}else this._isAllSpritesGroup||(this.p.allSprites.subgroups.push(this),this.parent=0);this.animations=new this.p.SpriteAnimations,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={};let s=this;this.Sprite,this.Sprite=class extends this.p.Sprite{constructor(){super(s,...arguments)}},this.GroupSprite=this.Sprite,this.Group,this.Group=class extends this.p.Group{constructor(){super(s,...arguments)}},this.Subgroup=this.Group,this.mouse={presses:null,pressing:null,pressed:null,holds:null,holding:null,held:null,released:null,hovers:null,hovering:null,hovered:null};for(let t in this.mouse)this.mouse[t]=function(e){for(let i of s)if(i.mouse[t](e))return!0;return!1};let r=[...this.p.Sprite.propsAll,"spriteSheet"];for(let t of r)"ani"!=t&&"velocity"!=t&&Object.defineProperty(this,t,{get(){let e=s["_"+t],i=s.length-1;if(void 0===e&&!s._isAllSpritesGroup){let r=this.p.p5play.groups[s.parent];r&&(e=r[t],i=r.length-1)}return e},set(e){s["_"+t]=e;for(let i=0;it&&(t=e._layer);return t}get ani(){return this._ani}set ani(t){this.addAni(t);for(let e of this)e.changeAni(t)}get animation(){return this._ani}set animation(t){this.ani=t}get anis(){return this.animations}get img(){return this._ani.frameImage}set img(t){this.ani=t}get image(){return this._ani.frameImage}set image(t){this.ani=t}set amount(t){let e=t-this.length,i=e>0;e=Math.abs(e);for(let t=0;t0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){for(let e of this)e._removeContactsWith(t)}_ensureOverlap(t,e){if(!t)throw new v("Group.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Group.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Group.overlap",1,[e]);if(!this._hasSensors){for(let t of this)t._hasSensors||t.addDefaultSensors();this._hasSensors=!0}if(!t._hasSensors)if(t instanceof this.p.Sprite)t.addDefaultSensors();else{for(let e of t)e._hasSensors||e.addDefaultSensors();t._hasSensors=!0}if(1!=this._hasOverlap[t._uid]){this._removeContactsWith(t),this._hasOverlap[t._uid]=!0;for(let e of this)e._hasOverlap[t._uid]=!0}if(1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}applyForce(){for(let t of this)t.applyForce(...arguments)}applyForceScaled(){for(let t of this)t.applyForceScaled(...arguments)}attractTo(){for(let t of this)t.attractTo(...arguments)}applyTorque(){for(let t of this)t.applyTorque(...arguments)}move(t,e,i){let s=[];for(let r of this)s.push(r.move(t,e,i));return Promise.all(s)}moveTo(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}let s=this._resetCentroid(),r=[];for(let o of this){let h={x:o.x-s.x+t,y:o.y-s.y+e};r.push(o.moveTo(h.x,h.y,i))}return Promise.all(r)}moveTowards(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveTowards(r.x,r.y,i)}}}moveAway(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveAway(r.x,r.y,i)}}}push(...t){for(let e of t){if(!(e instanceof this.p.Sprite))throw new Error("you can only add sprites to a group, no "+typeof e+"s");for(let t in this._hasOverlap){let i=this._hasOverlap[t];i&&!e._hasSensors&&e.addDefaultSensors(),e._hasOverlap[t]=i}super.push(e),this.parent&&this.p.p5play.groups[this.parent].push(e),e.groups.push(this)}return this.length}size(){return this.length}toString(){return"g"+this.idNum}cull(t,e,i,s,r){if(void 0===i){r=e,t=e=i=s=t}if(isNaN(t)||isNaN(e)||isNaN(i)||isNaN(s))throw new TypeError("The culling boundary must be defined with numbers");if(r&&"function"!=typeof r)throw new TypeError("The callback to group.cull must be a function");let o=this.p.camera.x-this.p.world.hw/this.p.camera.zoom,h=this.p.camera.y-this.p.world.hh/this.p.camera.zoom,n=-i+o,a=-t+h,l=this.p.width+s+o,p=this.p.height+e+h,d=0;for(let t=0;tl||e.y>p)&&(d++,r?r(e,d):e.remove(),e.removed&&t--))}return d}remove(t){if(void 0===t){for(;this.length>0;)this[0].remove();return}let e;if(e="number"==typeof t?t>=0?t:this.length+t:this.indexOf(t),-1!=e){let t=this[e];if(!t.removed){let e=t.groups.findIndex((t=>t._uid==this._uid));t.groups.splice(e,1)}return this.splice(e,1),t}throw new Error("Sprite not found in group")}removeAll(){this.remove()}draw(){let t=[...this];t.sort(((t,e)=>t._layer-e._layer));for(let e=0;e(t.getShape().testPoint(t.getBody().getTransform(),h)&&a.push(t),!0))),r??=this.p.allSprites;let l=[];if(a.length>0)for(let t of r)t.body&&a.includes(t.body.m_fixtureList)&&t._cameraActiveWhenDrawn==o&&l.push(t);return l}getSpriteAt(t,e,i){let s=this.getSpritesAt(t,e,i);return s.sort(((t,e)=>-1*(t._layer-e._layer))),s[0]}_beginContact(t){let e=t.m_fixtureA,i=t.m_fixtureB,s="_collisions";e.m_isSensor&&(s="_overlappers"),e=e.m_body.sprite,i=i.m_body.sprite,e[s][i._uid]=0,i[s][e._uid]=0;for(let t of i.groups)(!e[s][t._uid]||e[s][t._uid]<0)&&(t[s][e._uid]=0,e[s][t._uid]=0);for(let t of e.groups){(!i[s][t._uid]||i[s][t._uid]<0)&&(t[s][i._uid]=0,i[s][t._uid]=0);for(let e of i.groups)(!t[s][e._uid]||t[s][e._uid]<0)&&(t[s][e._uid]=0,e[s][t._uid]=0)}}_endContact(t){let e=t.m_fixtureA,i=t.m_fixtureB,s="_collisions";e.m_isSensor&&(s="_overlappers"),e=e.m_body.sprite,i=i.m_body.sprite,e[s][i._uid]=0!=e[s][i._uid]?-2:-3,i[s][e._uid]=0!=i[s][e._uid]?-2:-3;for(let t of i.groups){let i=!1;for(let r of t)if(r[s][e._uid]>=0){i=!0;break}i||(t[s][e._uid]=0!=t[s][e._uid]?-2:-3,e[s][t._uid]=0!=e[s][t._uid]?-2:-3)}for(let t of e.groups){let e=!1;for(let r of t)if(r[s][i._uid]>=0){e=!0;break}if(!e){t[s][i._uid]=0!=t[s][i._uid]?-2:-3,i[s][t._uid]=0!=i[s][t._uid]?-2:-3;for(let e of i.groups)t[s][e._uid]=0!=t[s][e._uid]?-2:3,e[s][t._uid]=0!=e[s][t._uid]?-2:3}}}_findContact(t,e,i,s){let r=e[t][i._uid];if(r&&(!s||!0!==r))return r;let o=i instanceof this.p.Sprite;if(o)for(let o of i.groups)if(r=e[t][o._uid],r&&(!s||!0!==r))return r;if(e instanceof this.p.Sprite)for(let h of e.groups){if(r=h[t][i._uid],r&&(!s||!0!==r))return r;if(o)for(let o of i.groups)if(r=h[t][o._uid],r&&(!s||!0!==r)&&(h._uid!=o._uid||e._uid{for(let t=0;t0&&(t=t<.1?this.p.map(t,0,.1,30,4):t<.5?this.p.map(t,.1,.5,4,2.5):t<.8?this.p.map(t,.5,.8,2.5,1):t<.9?this.p.map(t,.8,.9,1,.5):this.p.map(t,.9,1,.5,.2)),this._springiness=t,"wheel"==this.type?this._j.setSpringFrequencyHz(t):this._j.setFrequency(t)}get damping(){return"wheel"!=this.type?this._j.getDampingRatio():this._j.getSpringDampingRatio()}set damping(t){"wheel"==this.type?this._j.setSpringDampingRatio(t):this._j.setDampingRatio(t)}get speed(){return this._j.getJointSpeed()}set speed(t){this._j.isMotorEnabled()||this._j.enableMotor(!0),this._j.setMotorSpeed(t)}get motorSpeed(){return this._j.getMotorSpeed()}get enableMotor(){return this._j.isMotorEnabled()}set enableMotor(t){this._j.enableMotor(t)}get maxPower(){return this._j.getMaxMotorTorque()}set maxPower(t){!this._j.isMotorEnabled()&&t&&this._j.enableMotor(!0),this._j.setMaxMotorTorque(t),t||this._j.enableMotor(!1)}get power(){return this._j.getMotorTorque()}get collideConnected(){return this._j.getCollideConnected()}set collideConnected(t){this._j.m_collideConnected=t}remove(){this._removed||(this.spriteA.joints.splice(this.spriteA.joints.indexOf(this),1),this.spriteB.joints.splice(this.spriteB.joints.indexOf(this),1),this.p.world.destroyJoint(this._j),this._removed=!0)}},this.GlueJoint=class extends this.Joint{constructor(t,e){super(...arguments,"glue")}},this.DistanceJoint=class extends this.Joint{constructor(t,i){super(...arguments,"distance");let s=e.DistanceJoint({},t.body,i.body,t.body.getWorldCenter(),i.body.getWorldCenter());this._createJoint(s)}_display(){let t,e;(this.offsetA.x||this.offsetA.y)&&(t=this.spriteA.body.getWorldPoint(this._j.m_localAnchorA),t=r(t.x,t.y,this.spriteA.tileSize)),(this.offsetB.x||this.offsetB.y)&&(e=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB),e=r(e.x,e.y,this.spriteB.tileSize)),this._draw(t?t.x:this.spriteA.x,t?t.y:this.spriteA.y,e?e.x:this.spriteB.x,e?e.y:this.spriteB.y),this.visible=null}},this.WheelJoint=class extends this.Joint{constructor(t,i){super(...arguments,"wheel");let s=e.WheelJoint({maxMotorTorque:1e3,frequencyHz:4,dampingRatio:.7},t.body,i.body,i.body.getWorldCenter(),new e.Vec2(0,1));this._createJoint(s),this._angle="degrees"==this.p._angleMode?90:1.5707963267948966}_display(){let t,e,i=this.spriteA.x,s=this.spriteA.y;if(this.offsetB.x||this.offsetB.y){let i=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB);i=r(i.x,i.y,this.spriteB.tileSize),t=i.x,e=i.y}else t=this.spriteB.x,e=this.spriteB.y;let o=this.p.tan(this.spriteA.rotation),h=this.p.tan(this._angle+this.spriteA.rotation),n=(e-s+o*i-h*t)/(o-h),a=o*(n-i)+s;this._draw(n,a,t,e),this.visible=null}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new e.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=e.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}},this.HingeJoint=class extends this.Joint{constructor(t,i){super(...arguments,"hinge");let s=e.RevoluteJoint({},t.body,i.body,t.body.getWorldCenter());this._createJoint(s)}_display(){const t=this.offsetA.x,e=this.offsetA.y,i=this.spriteA.rotation,s=t*this.p.cos(i)-e*this.p.sin(i),r=t*this.p.sin(i)+e*this.p.cos(i);this._draw(this.spriteA.x+s,this.spriteA.y+r),this.visible=null}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){let t=this._j.getLowerLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_lowerAngle=t}get upperLimit(){let t=this._j.getUpperLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_upperAngle=t}get angle(){let e=this._j.getJointAngle();return"radians"==this.p._angleMode?e:t.radians(e)}},this.RevoluteJoint=this.HingeJoint,this.SliderJoint=class extends this.Joint{constructor(t,i){super(...arguments,"slider");let s=e.PrismaticJoint({lowerTranslation:-1,upperTranslation:1,enableLimit:!0,maxMotorForce:50,motorSpeed:0,enableMotor:!0},t.body,i.body,t.body.getWorldCenter(),new e.Vec2(1,0));this._createJoint(s),this._angle=0}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new e.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=e.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){return this._j.getLowerLimit()/this.spriteA.tileSize*i}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/i,this._j.setLimits(t,this._j.getUpperLimit())}get upperLimit(){return this._j.getUpperLimit()/this.spriteA.tileSize*i}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/i,this._j.setLimits(this._j.getLowerLimit(),t)}},this.PrismaticJoint=this.SliderJoint,this.RopeJoint=class extends this.Joint{constructor(t,i){super(...arguments,"rope");let s=e.RopeJoint({maxLength:1},t.body,i.body,t.body.getWorldCenter());this._createJoint(s),this._j.m_localAnchorB.x=0,this._j.m_localAnchorB.y=0}get maxLength(){return t=this._j.getMaxLength(),e=this.spriteA.tileSize,t/e*i;var t,e}set maxLength(t){var e,s;this._j.setMaxLength((e=t,s=this.spriteA.tileSize,e*s/i))}};class l{constructor(){let t=this;Object.defineProperties(this,{x:{get:()=>t._x,set(e){e!=t._x&&(t._x=e,t._avg=.5*(t._x+t._y))},configurable:!0,enumerable:!0},y:{get:()=>t._y,set(e){e!=t._y&&(t._y=e,t._avg=.5*(t._x+t._y))},configurable:!0,enumerable:!0},_x:{value:1,enumerable:!1,writable:!0},_y:{value:1,enumerable:!1,writable:!0},_avg:{value:1,enumerable:!1,writable:!0}})}valueOf(){return this._avg}}!function(){let t=new Float32Array(1),e=new Int32Array(t.buffer)}();function p(t){return!/^(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*(?:(?:(?:async\s(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*)?function|class)(?:\s|(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*)|(?:[_$\w][\w0-9_$]*\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\()|(?:\[\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*(?:(?:['][^']+['])|(?:["][^"]+["]))\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\]\())/.test(t.toString())}function d(t,e){return"triangle"==e?t=[t,-120,3]:"square"==e?t=[t,-90,4]:"pentagon"==e?t=[t,-72,5]:"hexagon"==e?t=[t,-60,6]:"septagon"==e?t=[t,-51.4285714286,7]:"octagon"==e?t=[t,-45,8]:"enneagon"==e?t=[t,-40,9]:"decagon"==e?t=[t,-36,10]:"hendecagon"==e?t=[t,-32.7272727273,11]:"dodecagon"==e&&(t=[t,-30,12]),t}this.p5play.palettes??=[{a:"aqua",b:"black",c:"crimson",d:"darkviolet",e:"peachpuff",f:"olive",g:"green",h:"hotpink",i:"indigo",j:"navy",k:"khaki",l:"lime",m:"magenta",n:"brown",o:"orange",p:"pink",q:"turquoise",r:"red",s:"skyblue",t:"tan",u:"blue",v:"violet",w:"white",x:"gold",y:"yellow",z:"gray"}],this.colorPal=(e,i)=>{if(e instanceof p5.Color)return e;let s;return"number"==typeof i&&(i=t.p5play.palettes[i]),i??=t.p5play.palettes[0],i&&(s=i[e]),""===s||"."===e||" "===e?t.color(0,0,0,0):t.color(s||e)},this.spriteArt=(e,i,s)=>{i??=1,"number"==typeof s&&(s=t.p5play.palettes[s]),s??=t.p5play.palettes[0];let r=e;"string"==typeof e&&(r=(e=(e=(e=e.trim()).replace(/\r*\n\t+/g,"\n")).replace(/\s+$/g,"")).split("\n"));let o=0;for(let t of r)t.length>o&&(o=t.length);let h=r.length,n=t.createImage(o*i,h*i);n.loadPixels();for(let t=0;tnew Promise(t?e=>{setTimeout(e,t)}:requestAnimationFrame),this.sleep=t=>this.delay(t),this.play=t=>{if(!t.play)throw new Error("Tried to play your input but it wasn't a sound object: "+t);return new Promise(((e,i)=>{t.play(),t.onended((()=>e()))}))},this.p5play.playIntro=async function(){if(document.getElementById("p5play-intro"))return;t._incrementPreload();let e=document.createElement("div");e.id="p5play-intro",e.style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 1000; background-color: black;";let i=document.createElement("img");i.src="https://p5play.org/v3/made_with_p5play.png",i.style="position: absolute; top: 50%; left: 50%; width: 40vh; height: 20vh; margin-left: -20vh; margin-top: -10vh; z-index: 1000; opacity: 0; transition: opacity 0.1s ease-in-out;",document.body.append(e),e.append(i),await t.delay(100),i.style.opacity="1",i.style.transition="scale 1.4s, opacity 0.4s ease-in-out",i.style.scale="1.1",await t.delay(1100),i.style.opacity="0",await t.delay(300),e.style.display="none",e.remove(),document.getElementById("p5play-intro")?.remove(),t._decrementPreload()};{let t=location.hostname;switch(t){case"":case"127.0.0.1":case"localhost":case"p5play.org":case"editor.p5js.org":case"codepen.io":case"codera.app":case"cdpn.io":case"glitch.com":case"replit.com":case"stackblitz.com":case"jsfiddle.net":case"aijs-912fe.web.app":break;default:if(/^[\d\.]+$/.test(t)||t.endsWith("stackblitz.io")||t.endsWith("glitch.me")||t.endsWith("repl.co")||t.endsWith("codehs.com")||t.endsWith("openprocessing.org")||location.origin.endsWith("preview.p5js.org"))break;this.p5play.playIntro()}}let u=p5.disableFriendlyErrors;p5.disableFriendlyErrors=!0,this.canvas=this.canvas;const c=this.createCanvas;this.createCanvas=function(){let e,i,s,r,o=[...arguments],h=!1,n=!1;if("string"==typeof o[0]&&(o[0].includes(":")?s=o[0].split(":"):(o[2]=o[0],o[0]=void 0),"fullscreen"==o[1]&&(h=!0)),o[0]?"number"==typeof o[0]&&"number"!=typeof o[1]&&(o[2]=o[1],o[1]=o[0]):(o[0]=window.innerWidth,o[1]=window.innerHeight,h=!0),"string"==typeof o[2]){let t=o[2].toLowerCase();"p2d"!=t&&"webgl"!=t&&(t=t.split(" "),o.pop()),"pixelated"==t[0]&&(n=!0,t[1]?r=Number(t[1].slice(1)):h=!0,s=[o[0],o[1]]),"fullscreen"==t[0]&&(h=!0)}if(s){let t=Number(s[0]),h=Number(s[1]);r?(e=t*r,i=h*r):(e=window.innerWidth,i=window.innerWidth*(h/t),i>window.innerHeight&&(e=window.innerHeight*(t/h),i=window.innerHeight)),e=Math.round(e),i=Math.round(i),n||(o[0]=e,o[1]=i)}let a=c.call(t,...o);this.canvas.tabIndex=0,this.canvas.w=o[0],this.canvas.h=o[1],this.canvas.addEventListener("keydown",(function(t){" "!=t.key&&"/"!=t.key&&"ArrowUp"!=t.key&&"ArrowDown"!=t.key&&"ArrowLeft"!=t.key&&"ArrowRight"!=t.key||t.preventDefault()})),this.canvas.addEventListener("mouseover",(()=>{this.mouse.isOnCanvas=!0,this.mouse.active=!0})),this.canvas.addEventListener("mouseleave",(()=>{this.mouse.isOnCanvas=!1})),this.canvas.addEventListener("touchstart",(t=>t.preventDefault())),this.canvas.addEventListener("contextmenu",(t=>t.preventDefault())),this.canvas.resize=this.resizeCanvas,this.world.resize(),this.camera.x=this.world.hw,this.camera.y=this.world.hh,u||(p5.disableFriendlyErrors=!1);let l="\n.p5Canvas, .q5Canvas {\n\toutline: none;\n\t-webkit-touch-callout: none;\n\t-webkit-text-size-adjust: none;\n\t-webkit-user-select: none;\n\toverscroll-behavior: none;\n}\nmain {\n\toverscroll-behavior: none;\n}";h&&(l="html,\nbody,\n"+l,l+="\nhtml, body {\n\tmargin: 0;\n\tpadding: 0;\n\toverflow: hidden;\n\theight: 100%;\n}\nmain {\n\tmargin: auto;\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\talign-content: center;\n\tjustify-content: center;\n\theight: 100%;\n}"),n&&(l+=`\n#${this.canvas.id} {\n\timage-rendering: pixelated;\n\twidth: ${e}px!important;\n\theight: ${i}px!important;\n}`);let p=document.createElement("style");p.innerHTML=l,document.head.appendChild(p),n&&(t.pixelDensity(1),t.noSmooth());let d=navigator.userAgent.indexOf("iPhone OS");if(d>-1){let e=navigator.userAgent.substring(d+10,d+12);this.p5play.version=e,e<16&&t.pixelDensity(1),this.p5play.os.platform="iOS",this.p5play.os.version=e}else void 0!==navigator.userAgentData&&(this.p5play.os.platform=navigator.userAgentData.platform);return a},this.Canvas=class{constructor(t,e,i){}get w(){}get width(){}get h(){}get height(){}resize(){}},this.Canvas=function(){return t.createCanvas(...arguments)};const _=this.resizeCanvas;this.resizeCanvas=(t,e)=>{_.call(this,t,e),this.world.resize(),this.camera._pos.x=this.world.hw,this.camera._pos.y=this.world.hh};const f=this.background;this.background=function(){let t,e=arguments;1==e.length&&("string"==typeof e[0]||e[0]instanceof p5.Color)&&(t=this.colorPal(e[0])),void 0!==t?f.call(this,t):f.call(this,...e)};const g=this.fill;this.fill=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?g.call(this,t):g.call(this,...e)};const y=this.stroke;this.stroke=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?y.call(this,t):y.call(this,...e)},this.p5play.images={onLoad:t=>{}},this.p5play.disableImages=!1;const m=this.loadImage;this.loadImage=this.loadImg=function(){if(this.p5play.disableImages)return t._decrementPreload(),{w:16,width:16,h:16,height:16,pixels:[]};let e,i=arguments,s=i[0],r=t.p5play.images[s];if("function"==typeof i[i.length-1]&&(e=i[i.length-1]),r)return 1==r.width&&1==r.height||!r.pixels.length?e?(r.cbs.push(e),r.calls++):t._decrementPreload():(e&&e(),t._decrementPreload()),r;return r=m.call(t,s,(e=>{e.w=e.width,e.h=e.height;for(let t of e.cbs)t(e);for(let i=1;ii[e])),o+=h,p5._friendlyError(o,t)}}this.allSprites=new this.Group,this.world=new this.World,this.camera=new this.Camera,this.InputDevice=class{constructor(){this.holdThreshold=12,this._default=0}_init(t){for(let e of t)this[e]=0}_ac(t){return t}presses(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),1==this[t]||-2==this[t]}pressing(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),-2==this[t]?1:this[t]>0?this[t]:0}pressed(t){return this.released(t)}holds(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]==this.holdThreshold}holding(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]>=this.holdThreshold?this[t]:0}held(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),-3==this[t]}released(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]<=-1}releases(t){return this.released(t)}},this._Mouse=class extends this.InputDevice{constructor(){super(),this._default="left";let t=this;this._position={get x(){return t.x},set x(e){t.x=e},get y(){return t.y},set y(e){t.y=e}},this.x,this.y,this.left,this.center,this.right;this._init(["x","y","left","center","right"]),this.drag={left:0,center:0,right:0},this.isOnCanvas=!1,this.active=!1,this._visible=!0,this._cursor="default"}_ac(t){return"left"==(t=t.toLowerCase()).slice(0,4)?t="left":"right"==t.slice(0,5)?t="right":"middle"==t.slice(0,6)&&(t="center"),t}get pos(){return this._position}get position(){return this._position}get cursor(){return t.canvas.style.cursor}set cursor(e){e!=this._cursor&&(t.cursor(e),this._cursor=e)}get visible(){return this._visible}set visible(e){this._visible=e,t.canvas.style.cursor=e?"default":"none"}drags(t){return t??=this._default,1==this.drag[t]}dragging(t){return t??=this._default,this.drag[t]>0?this.drag[t]:0}dragged(t){return t??=this._default,-1==this.drag[t]}},this.mouse=new this._Mouse,this._SpriteMouse=class extends this._Mouse{constructor(){super(),this.hover=0}hovers(){return 1==this.hover}hovering(){return this.hover>0?this.hover:0}hovered(){return-1==this.hover}};const b=function(t){if(this.mouse[t]++,this.mouse.active=!0,this.world.mouseSprites.length){let e=this.world.mouseSprite;e&&(e.mouse[t]=0,e.mouse.drag[t]=0),e=this.world.mouseSprites[0],e.mouse[t]=1,this.world.mouseSprite=e}},S=t._onmousedown;t._onmousedown=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),b.call(this,e),S.call(this,t)};const A=t._ontouchstart;t._ontouchstart=function(t){b.call(this,"left"),A.call(this,t)};const C=function(t){let e=this.mouse;if(e[t]>0&&e.drag[t]<=0){e.drag[t]=1,e._isDragging=!0;let i=this.world.mouseSprite?.mouse;i&&(i.drag[t]=1,i._isDragging=!0)}},k=t._onmousemove;t._onmousemove=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),C.call(this,e),k.call(this,t)};const z=function(t){let e=this.mouse;e[t]>=e.holdThreshold?e[t]=-3:e[t]>1?e[t]=-1:e[t]=-2;let i=this.world.mouseSprite?.mouse;i&&(i.hover>1?(i[t]>=this.mouse.holdThreshold?i[t]=-3:i[t]>1?i[t]=-1:i[t]=-2,i.drag[t]>0&&(i.drag[t]=i[t])):(i[t]=0,i.drag[t]=0))},j=t._onmouseup;t._onmouseup=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),z.call(this,e),j.call(this,t)};const M=t._ontouchend;if(t._ontouchend=function(t){z.call(this,"left"),M.call(this,t)},delete this._Mouse,this._KeyBoard=class extends this.InputDevice{#e;constructor(){super(),this._default=" ",this.alt=0,this.arrowUp=0,this.arrowDown=0,this.arrowLeft=0,this.arrowRight=0,this.backspace=0,this.capsLock=0,this.control=0,this.enter=0,this.meta=0,this.shift=0,this.tab=0;let t=this._simpleKeyControls={arrowUp:"up",arrowDown:"down",arrowLeft:"left",arrowRight:"right"};t.w=t.W="up",t.s=t.S="down",t.a=t.A="left",t.d=t.D="right",t.i=t.I="up2",t.k=t.K="down2",t.j=t.J="left2",t.l=t.L="right2"}_ac(t){if(1!=t.length){if(!isNaN(t)){if(38==t)return"arrowUp";if(40==t)return"arrowDown";if(37==t)return"arrowLeft";if(39==t)return"arrowRight";if(t>=10)throw new Error("Use key names with the keyboard input functions, not keyCode numbers!");return t}t=t.replaceAll(/[ _-]/g,"")}if(1!=(t=t.toLowerCase()).length){if("arrowup"==t)return"arrowUp";if("arrowdown"==t)return"arrowDown";if("arrowleft"==t)return"arrowLeft";if("arrowright"==t)return"arrowRight";if("capslock"==t)return"capsLock"}return t}_pre(t){(!this[t]||this[t]<0)&&(this[t]=1)}_rel(t){this[t]>=this.holdThreshold?this[t]=-3:this[t]>1?this[t]=-1:this[t]=-2}get cmd(){return this.meta}get command(){return this.meta}get ctrl(){return this.control}get space(){return this[" "]}get spacebar(){return this[" "]}get opt(){return this.alt}get option(){return this.alt}get win(){return this.meta}get windows(){return this.meta}},this.kb=new this._KeyBoard,delete this._KeyBoard,this.keyboard=this.kb,navigator.keyboard){const t=navigator.keyboard;window==window.top?t.getLayoutMap().then((t=>{"w"!=t.get("KeyW")&&(this.p5play.standardizeKeyboard=!0)})):this.p5play.standardizeKeyboard=!0}else this.p5play.standardizeKeyboard=!0;function T(t){let e=t.code;return 4==e.length&&"Key"==e.slice(0,3)?e[3].toLowerCase():t.key}const L=t._onkeydown;t._onkeydown=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(t)),e.length>1)e=e[0].toLowerCase()+e.slice(1);else{let t=e.toLowerCase(),i=e.toUpperCase();t!=i&&(e!=i?this.kb._pre(i):this.kb._pre(t))}this.kb._pre(e);let i=this.kb._simpleKeyControls[e];i&&this.kb._pre(i),L.call(this,t)};const D=t._onkeyup;t._onkeyup=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(t)),e.length>1)e=e[0].toLowerCase()+e.slice(1);else{let t=e.toLowerCase(),i=e.toUpperCase();t!=i&&(e!=i?this.kb._rel(i):this.kb._rel(t))}this.kb._rel(e);let i=this.kb._simpleKeyControls[e];if(i&&this.kb._rel(i),t.shiftKey){let t=e.toLowerCase();this.kb[t]>0&&this.kb._rel(t)}D.call(this,t)},this._Contro=class extends this.InputDevice{constructor(t){super(),this._default="a",this.connected=!0;this._init(["a","b","x","y","l","r","lt","rt","select","start","lsb","rsb","up","down","left","right","leftTrigger","rightTrigger"]),this.leftStick={x:0,y:0},this.rightStick={x:0,y:0},this._btns={a:0,b:1,x:2,y:3,l:4,r:5,lt:6,rt:7,select:8,start:9,lsb:10,rsb:11,up:12,down:13,left:14,right:15},this._axes={leftStick:{x:0,y:1},rightStick:{x:2,y:3},leftTrigger:4,rightTrigger:5},t.id.includes("GuliKit")&&(this._btns.a=1,this._btns.b=0,this._btns.x=3,this._btns.y=2),this.gamepad=t,this.id=t.id}_ac(t){return"lb"==(t=t.toLowerCase())?t="l":"rb"==t?t="r":"leftstickbutton"==t?t="lsb":"rightstickbutton"==t&&(t="rsb"),t}_update(){if(!this.connected)return;if(this.gamepad=navigator.getGamepads()[this.gamepad.index],!this.gamepad?.connected)return;let t=this.gamepad;for(let e in this._btns){let i=this._btns[e];t.buttons[i].pressed?this[e]++:this[e]=this[e]>0?-1:0}return this.leftStick.x=t.axes[this._axes.leftStick.x],this.leftStick.y=t.axes[this._axes.leftStick.y],this.rightStick.x=t.axes[this._axes.rightStick.x],this.rightStick.y=t.axes[this._axes.rightStick.y],void 0!==t.axes[this._axes.leftTrigger]?(this.leftTrigger=t.axes[this._axes.leftTrigger],this.rightTrigger=t.axes[this._axes.rightTrigger]):(this.leftTrigger=t.buttons[this._btns.lt].value,this.rightTrigger=t.buttons[this._btns.rt].value),!0}get ls(){return this.leftStick}get rs(){return this.rightStick}get lb(){return this.l}get rb(){return this.r}get leftStickButton(){return this.lsb}get rightStickButton(){return this.rsb}},this._Contros=class extends Array{constructor(){super();let t=this;window.addEventListener("gamepadconnected",(e=>{t._onConnect(e.gamepad)})),window.addEventListener("gamepaddisconnected",(e=>{t._onDisconnect(e.gamepad)})),this.presses,this.pressing,this.pressed,this.holds,this.holding,this.held,this.released;let e=["presses","pressing","pressed","holds","holding","held","released"];for(let t of e)this[t]=e=>{if(this[0])return this[0][t](e)};this.a=0,this.b=0,this.x=0,this.y=0,this.l=0,this.r=0,this.lt=0,this.rt=0,this.select=0,this.start=0,this.lsb=0,this.rsb=0,this.up=0,this.down=0,this.left=0,this.right=0,this.leftTrigger=0,this.rightTrigger=0,this.lb=0,this.rb=0,this.leftStickButton=0,this.rightStickButton=0;let i=["connected","a","b","x","y","l","r","lt","rt","select","start","lsb","rsb","up","down","left","right","leftTrigger","rightTrigger","lb","rb","leftStickButton","rightStickButton"];for(let e of i)Object.defineProperty(this,e,{get:()=>t[0]?t[0][e]:0});this.leftStick,this.rightStick,i=["leftStick","rightStick"];for(let e of i){this[e]={};for(let i of["x","y"])Object.defineProperty(this[e],i,{get:()=>t[0]?t[0][e][i]:0})}if(!navigator?.getGamepads)return;let s=navigator.getGamepads();for(let t of s)t&&this._onConnect(t)}_onConnect(e){if(!e)return;for(let t=0;tthis.p5play._fps,this.p5play._fpsArr=[60],this.renderStats=(t,e)=>{let i=this.p5play._renderStats;void 0===i.show&&(1==this.allSprites.tileSize||this.allSprites.tileSize>16?i.fontSize=16:i.fontSize=10,i.gap=1.25*i.fontSize,console.warn("renderStats() uses inaccurate FPS approximations. Even if your game runs at a solid 60hz display rate, the fps calculations shown may be lower. The only way to get accurate results is to use your web browser's performance testing tools.")),i.x=t||10,i.y=e||20,i.show=!0}})),p5.prototype.registerMethod("pre",(function(){this.p5play._fps&&(this.p5play._preDrawFrameTime=performance.now()),this.p5play.spritesDrawn=0,this.mouse.x=(this.mouseX-this.world.hw)/this.camera.zoom+this.camera.x,this.mouse.y=(this.mouseY-this.world.hh)/this.camera.zoom+this.camera.y,this.camera.mouse.x=this.mouseX,this.camera.mouse.y=this.mouseY,this.contro._update()})),p5.prototype.registerMethod("post",(function(){this.p5play._inPostDraw=!0,this.allSprites.autoCull&&this.allSprites.cull(1e4),this.allSprites._autoDraw&&(this.camera.on(),this.allSprites.draw(),this.camera.off()),this.allSprites._autoDraw??=!0;let t=this.p5play._renderStats;if(t.show){if(1==this.frameCount||this.frameCount%60==0){let t,e=this.p5play._fpsArr.reduce(((t,e)=>t+e));e=Math.round(e/this.p5play._fpsArr.length),this.p5play._fpsAvg=e,this.p5play._fpsMin=Math.min(...this.p5play._fpsArr),this.p5play._fpsMax=Math.max(...this.p5play._fpsArr),this.p5play._fpsArr=[],t=e>55?this.color(30,255,30):e>25?this.color(255,100,30):this.color(255,30,30),this.p5play._statsColor=t}this.p5play._fpsArr.push(this.getFPS()),this.push(),this.fill(0,0,0,128),this.rect(t.x-5,t.y-t.fontSize,8.5*t.fontSize,4*t.gap+5),this.fill(this.p5play._statsColor),this.textSize(t.fontSize),this.textFont("monospace");let e=t.x,i=t.y;this.text("sprites: "+this.p5play.spritesDrawn,e,i),this.text("fps avg: "+this.p5play._fpsAvg,e,i+t.gap),this.text("fps min: "+this.p5play._fpsMin,e,i+2*t.gap),this.text("fps max: "+this.p5play._fpsMax,e,i+3*t.gap),this.pop(),t.show=!1}this.world.autoStep&&this.world.step(),this.world.autoStep??=!0,this.allSprites._autoUpdate&&this.allSprites.update(),this.allSprites._autoUpdate??=!0;for(let t of this.allSprites)t.autoDraw??=!0,t.autoUpdate??=!0;for(let t in this.kb)"holdThreshold"!=t&&(this.kb[t]<0?this.kb[t]=0:this.kb[t]>0&&this.kb[t]++);let e=this.mouse,i=this.world.mouseSprite?.mouse;for(let t of["left","center","right"])e[t]<0?e[t]=0:e[t]>0&&e[t]++,i&&(i[t]=e[t]);if(this.world.mouseTracking){let t=this.world.getSpritesAt(e.x,e.y);t.sort(((t,e)=>-1*(t._layer-e._layer)));let s=this.world.getSpritesAt(this.camera.mouse.x,this.camera.mouse.y,this.allSprites,!1);s.sort(((t,e)=>-1*(t._layer-e._layer))),t=t.concat(s);for(let e=0;e0?i.mouse.hover=-1:i.mouse.hover<0&&(i.mouse.hover=0):i.mouse.hover++}let r=this.world.mouseSprite;if(e.left<=0&&e.center<=0&&e.right<=0)r=null,this.world.mouseSprite=null;else for(let t of["left","center","right"])e.drag[t]<0?e.drag[t]=0:e.drag[t]>0&&e.drag[t]++,i&&(i.drag[t]=e.drag[t],i.x=r.x-e.x,i.y=r.y-e.y);for(let e of this.world.mouseSprites)if(!(i?._isDragging&&e==r||t.includes(e))){let t=e.mouse;t.hover=-1,t.left=t.center=t.right=0}this.world.mouseSprites=t}this.camera.off(),this.p5play._fps&&(this.p5play._postDrawFrameTime=performance.now(),this.p5play._fps=Math.round(1e3/(this.p5play._postDrawFrameTime-this.p5play._preDrawFrameTime))||1),this.p5play._inPostDraw=!1}));