Skip to content

Commit

Permalink
1.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
quinton-ashley committed Oct 25, 2024
1 parent 46e7da5 commit cb0b10c
Show file tree
Hide file tree
Showing 96 changed files with 241 additions and 157 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion lang/en/learn/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 0-0

[**_Learn p5play: An Introduction to Object Oriented Programming_**](.) was written by Quinton Ashley, the creator of p5play v3. It's packed with beginner friendly reference documentation and interactive code examples.
[**_Learn p5play: An Introduction to Object Oriented Programming_**](.) was written by Quinton Ashley, the creator of p5play v3. It's packed with beginner friendly reference documentation and interactive code examples!

# 0-1

Expand Down
2 changes: 1 addition & 1 deletion lang/en/learn/sprite.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 0-0

## Setup
## Setup and Draw

The code inside the [q5.js](https://q5js.org) (or [p5.js](https://p5js.org)) `setup` function runs when the program starts. The `new Canvas()` constructor creates a section of the screen that the program can draw on.

Expand Down
Binary file modified learn/.DS_Store
Binary file not shown.
72 changes: 40 additions & 32 deletions learn/animation.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2 id="how-to-load-animations">How to load animations</h2>
function setup() {
new Canvas(500, 160);

cloudAni = loadAni('assets/cloud_breathing1.png', 9);
cloudAni = loadAni('assets/cloud_breathing1.webp', 9);
}

function draw() {
Expand All @@ -71,13 +71,13 @@ <h2 id="how-to-load-animations">How to load animations</h2>
new Canvas(500, 160);

shapeShifterAni = loadAnimation(
'assets/asterisk.png',
'assets/triangle.png',
'assets/square.png',
'assets/cloud.png',
'assets/star.png',
'assets/mess.png',
'assets/monster.png'
'assets/asterisk.webp',
'assets/triangle.webp',
'assets/square.webp',
'assets/cloud.webp',
'assets/star.webp',
'assets/mess.webp',
'assets/monster.webp'
);

shapeShifterAni.frameDelay = 10;
Expand All @@ -103,7 +103,7 @@ <h2 id="how-to-load-animations">How to load animations</h2>
function setup() {
new Canvas(500, 200);

splatAni = loadAnimation('assets/explode_sprite_sheet.png', { frameSize: [171, 158], frames: 11 });
splatAni = loadAnimation('assets/explode_sprite_sheet.webp', { frameSize: [342, 316], frames: 11 });
}

function draw() {
Expand All @@ -128,15 +128,18 @@ <h2 id="animating">Animating</h2>
function setup() {
new Canvas(500, 160);

ani = loadAni('assets/asterisk_explode0001.png', 11);
ani = loadAni('assets/asterisk_explode01.webp', 11);
}

function draw() {
clear();

if (kb.presses('s')) ani.stop();
if (kb.presses('p')) ani.play();
if (kb.presses('o')) ani.play(0);
if (kb.presses('space')) {
if (ani.playing) ani.pause();
else ani.play();
}

if (kb.presses('p')) ani.play(0);
if (kb.presses('ArrowDown')) ani.frameDelay--;
if (kb.presses('ArrowUp')) ani.frameDelay++;
if (kb.presses('r')) ani.rewind();
Expand Down Expand Up @@ -185,8 +188,8 @@ <h2 id="control-a-sprites-animation">Control a Sprite's Animation</h2>
new Canvas(500, 160);
ghost = new Sprite(250, 80, 120);

ghost.addAni('fly', 'assets/ghost_walk01.png', 3);
ghost.addAni('idle', 'assets/ghost_standing01.png', 7);
ghost.addAni('fly', 'assets/ghost_walk01.webp', 3);
ghost.addAni('idle', 'assets/ghost_standing01.webp', 7);
}

function draw() {
Expand Down Expand Up @@ -231,7 +234,7 @@ <h2 id="groups-with-animations">Groups with Animations</h2>
new Canvas(500, 160);

splats = new Group();
splats.addAni('assets/asterisk_explode0001.png', 11);
splats.addAni('assets/asterisk_explode0001.webp', 11);
}

function draw() {
Expand All @@ -248,20 +251,23 @@ <h2 id="groups-with-animations">Groups with Animations</h2>
<md id="md4-0">
<h2 id="sprite-sheets-with-multiple-animations">Sprite Sheets with Multiple Animations</h2>
<p>To load multiple animations from the same sprite sheet image, first set the
<code>spriteSheet</code> property of the sprite or group.</p>
<code>spriteSheet</code> property of the sprite or group.
</p>
<p>Next, use the <code>addAnimations</code> / <code>addAnis</code> function. They accept an object
that uses animation names as keys and sprite sheet atlases as values.</p>
<p>Using an atlas object is way easier than manually specifying the coordinates of every frame!</p>
<p>Atlas objects can have the following properties:</p>
<p><code>x</code>, <code>y</code>, <code>pos</code>, <code>w</code>/<code>width</code>,
<code>h</code>/<code>height</code>, <code>size</code>/<code>frameSize</code>, <code>row</code>,
<code>col</code>, <code>frames</code>/<code>frameCount</code>,
<code>delay</code>/<code>frameDelay</code>, and <code>rotation</code>.</p>
<code>delay</code>/<code>frameDelay</code>, and <code>rotation</code>.
</p>
<p>In the "hero" example the size of the hero sprite is set to 32x32 pixels in the
<code>Sprite</code> constructor. That size is used as a multiplier to the row value given.</p>
<code>Sprite</code> constructor. That size is used as a multiplier to the row value given.
</p>
<p>The <code>ani.offset</code> property is used to adjust the position of an animation relative to
the sprite's position.</p>
<p>Click this link to see the full <a href="/learn/assets/questKid.png" target="_blank">questKid</a>
<p>Click this link to see the full <a href="/learn/assets/questKid.webp" target="_blank">questKid</a>
sprite sheet used in the example.</p>
<p>If you'd like to truly appreciate p5play, compare the example code to <a
href="https://labs.phaser.io/view.html?src=src/animation/create%20animation%20from%20sprite%20sheet.js"
Expand All @@ -286,7 +292,7 @@ <h2 id="anis">anis</h2>

function preload() {
hero = new Sprite(125, 48, 32, 32);
hero.spriteSheet = 'assets/questKid.png';
hero.spriteSheet = 'assets/questKid.webp';
hero.anis.offset.x = 2;
hero.anis.frameDelay = 32;
hero.anis.demoMode = true;
Expand All @@ -304,7 +310,8 @@ <h2 id="anis">anis</h2>
}

function setup() {
new Canvas(250, 96, 'pixelated x2');
new Canvas(250, 96);
displayMode('default', 'pixelated', 2)
allSprites.pixelPerfect = true;
}

Expand All @@ -323,7 +330,7 @@ <h2 id="anis">anis</h2>

function preload() {
hero = new Sprite(62, 24, 32, 32);
hero.spriteSheet = 'assets/questKid.png';
hero.spriteSheet = 'assets/questKid.webp';
hero.anis.offset.x = 2;
hero.anis.frameDelay = 8;
hero.friction = 0;
Expand All @@ -339,7 +346,8 @@ <h2 id="anis">anis</h2>
}

function setup() {
new Canvas(124, 48, 'pixelated x4');
new Canvas(124, 48);
displayMode('normal', 'pixelated', 4);
allSprites.pixelPerfect = true;
}

Expand Down Expand Up @@ -370,7 +378,7 @@ <h2 id="animation-sequencing">Animation Sequencing</h2>

function preload() {
hero = new Sprite(62, 24, 32, 32);
hero.spriteSheet = 'assets/questKid.png';
hero.spriteSheet = 'assets/questKid.webp';
hero.anis.offset.x = 2;
hero.anis.offset.y = 2;
hero.anis.frameDelay = 8;
Expand Down Expand Up @@ -450,7 +458,7 @@ <h2 id="advanced-animation-sequencing">Advanced Animation Sequencing</h2>

function preload() {
hero = new Sprite(90, 24, 32, 32);
hero.spriteSheet = 'assets/questKid.png';
hero.spriteSheet = 'assets/questKid.webp';
hero.anis.offset.x = 2;
hero.anis.offset.y = 2;
hero.anis.frameDelay = 8;
Expand Down Expand Up @@ -505,15 +513,15 @@ <h2 id="advanced-animation-sequencing">Advanced Animation Sequencing</h2>
</article>

<script src="/v3/q5.min.js"></script>
<script src="/v3/planck.min.js"></script>
<script src="/v3/p5play.min.js"></script>
<script>
window.mie = { autoLoad: false };
<script src="/v3/planck.min.js"></script>
<script src="/v3/p5play.min.js"></script>
<script>
window.mie = { autoLoad: false };

</script>
<script src="/learn/mie.js"></script>
<script src="/learn/learn.js"></script>
<script src="/account/account.js"></script>
<script src="/learn/learn.js"></script>
<script src="/account/account.js"></script>
</body>

</html>
Binary file removed learn/assets/asterisk.png
Binary file not shown.
Binary file added learn/assets/asterisk.webp
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0001.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0002.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0003.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0004.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0005.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0006.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0007.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0008.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0009.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0010.png
Binary file not shown.
Binary file removed learn/assets/asterisk_explode0011.png
Binary file not shown.
Binary file added learn/assets/asterisk_explode01.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode02.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode03.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode04.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode05.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode06.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode07.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode08.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode09.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode10.webp
Binary file not shown.
Binary file added learn/assets/asterisk_explode11.webp
Binary file not shown.
Binary file removed learn/assets/cloud.png
Binary file not shown.
Binary file added learn/assets/cloud.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing1.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing1.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing2.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing2.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing3.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing3.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing4.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing4.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing5.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing5.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing6.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing6.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing7.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing7.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing8.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing8.webp
Binary file not shown.
Binary file removed learn/assets/cloud_breathing9.png
Binary file not shown.
Binary file added learn/assets/cloud_breathing9.webp
Binary file not shown.
Binary file removed learn/assets/explode_sprite_sheet.png
Binary file not shown.
Binary file added learn/assets/explode_sprite_sheet.webp
Binary file not shown.
Binary file removed learn/assets/face.png
Binary file not shown.
Binary file added learn/assets/face.webp
Binary file not shown.
Binary file removed learn/assets/ghost_standing01.png
Binary file not shown.
Binary file added learn/assets/ghost_standing01.webp
Binary file not shown.
Binary file removed learn/assets/ghost_standing02.png
Diff not rendered.
Binary file added learn/assets/ghost_standing02.webp
Binary file not shown.
Binary file removed learn/assets/ghost_standing03.png
Diff not rendered.
Binary file added learn/assets/ghost_standing03.webp
Binary file not shown.
Binary file removed learn/assets/ghost_standing04.png
Diff not rendered.
Binary file added learn/assets/ghost_standing04.webp
Binary file not shown.
Binary file removed learn/assets/ghost_standing05.png
Diff not rendered.
Binary file added learn/assets/ghost_standing05.webp
Binary file not shown.
Binary file removed learn/assets/ghost_standing06.png
Diff not rendered.
Binary file added learn/assets/ghost_standing06.webp
Binary file not shown.
Binary file removed learn/assets/ghost_standing07.png
Diff not rendered.
Binary file added learn/assets/ghost_standing07.webp
Binary file not shown.
Binary file removed learn/assets/ghost_walk01.png
Diff not rendered.
Binary file added learn/assets/ghost_walk01.webp
Binary file not shown.
Binary file removed learn/assets/ghost_walk02.png
Diff not rendered.
Binary file added learn/assets/ghost_walk02.webp
Binary file not shown.
Binary file removed learn/assets/ghost_walk03.png
Diff not rendered.
Binary file added learn/assets/ghost_walk03.webp
Binary file not shown.
Binary file removed learn/assets/ghost_walk04.png
Diff not rendered.
Binary file added learn/assets/ghost_walk04.webp
Binary file not shown.
Binary file removed learn/assets/mess.png
Diff not rendered.
Binary file added learn/assets/mess.webp
Binary file not shown.
Binary file removed learn/assets/monster.png
Diff not rendered.
Binary file added learn/assets/monster.webp
Binary file not shown.
Binary file removed learn/assets/questKid.png
Diff not rendered.
Binary file added learn/assets/questKid.webp
Binary file not shown.
Binary file removed learn/assets/square.png
Diff not rendered.
Binary file added learn/assets/square.webp
Binary file not shown.
Binary file removed learn/assets/star.png
Diff not rendered.
Binary file added learn/assets/star.webp
Binary file not shown.
Binary file removed learn/assets/triangle.png
Diff not rendered.
Binary file added learn/assets/triangle.webp
Binary file not shown.
55 changes: 30 additions & 25 deletions learn/sprite.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

<div id="page-0" class="page">
<md id="md0-0">
<h2 id="setup">Setup</h2>
<p>The code inside the <a href="https://q5js.org" target="_blank">q5.js</a> (or <a
href="https://p5js.org" target="_blank">p5.js</a>) <code>setup</code> function runs when the
<h2 id="setup-and-draw">Setup and Draw</h2>
<p>The code inside the <a href="https://q5js.org" target="_blank">q5.js</a> (or <a href="https://p5js.org"
target="_blank">p5.js</a>) <code>setup</code> function runs when the
program starts. The <code>new Canvas()</code> constructor creates a section of the screen that the
program can draw on.</p>
<p>The q5 <code>draw</code> function is run 60 times per second by default. The <code>background</code>
Expand Down Expand Up @@ -176,7 +176,8 @@ <h2 id="sprite-physics">Sprite physics</h2>
Setting a sprite's collider
type to <code>'none'</code> makes it have no collider.</p>
<p>The collider type can also be set using the first letter of the collider type name: <code>'d'</code>,
<code>'s'</code>, <code>'k'</code>, or <code>'n'</code>.</p>
<code>'s'</code>, <code>'k'</code>, or <code>'n'</code>.
</p>
<p>Click the reload icon on the top right corner of a code example to replay it!</p>
</md>
<script type="mie/p5" id="dynamic-and-static-colliders" base-2="" horiz="" lines="16">
Expand Down Expand Up @@ -292,7 +293,7 @@ <h2 id="sprites-with-an-image">Sprites with an Image</h2>

monster = new Sprite();
monster.diameter = 70;
monster.image = 'assets/monster.png';
monster.image = 'assets/monster.webp';
monster.image.offset.y = 6;
}

Expand Down Expand Up @@ -351,7 +352,7 @@ <h2 id="try-it">Try it!</h2>
..yyyyyy`;

smiley = new Sprite();
smiley.img = spriteArt(smileText, 16);
smiley.img = spriteArt(smileText, 32);
}

function draw() {
Expand All @@ -371,7 +372,7 @@ <h2 id="try-it">Try it!</h2>
`;

let alpha = new Sprite();
alpha.img = spriteArt(alphaText, 10);
alpha.img = spriteArt(alphaText, 20);

background(20);
noLoop();
Expand All @@ -391,8 +392,8 @@ <h2 id="custom-colors">Custom Colors</h2>
define a color for each letter you use in your pixel art. To create a color use the q5 <a
href="https://p5js.org/reference/p5/color" target="_blank"><code>color</code></a> function which
accepts RGB (red, green, blue) values or HEX color codes.</p>
<p>The easiest way to find colors is to use a <a
href="https://www.google.com/search?q=google+color+picker" target="_blank">color picker</a>.</p>
<p>The easiest way to find colors is to use a <a href="https://www.google.com/search?q=google+color+picker"
target="_blank">color picker</a>.</p>
</md>
<script type="mie/p5" id="blue-smiley" lines="20">
let smiley;
Expand All @@ -413,7 +414,7 @@ <h2 id="custom-colors">Custom Colors</h2>
};

smiley = new Sprite();
smiley.img = spriteArt(smileText, 16, palette);
smiley.img = spriteArt(smileText, 32, palette);
}

function draw() {
Expand Down Expand Up @@ -466,7 +467,8 @@ <h2 id="sprite-movement">Sprite movement</h2>
</script>
<md id="md3-2">
<p>All the other movement methods on this page change the sprite's <code>velocity</code>, aka
<code>vel</code>, which is its rate of motion along the x and y axis.</p>
<code>vel</code>, which is its rate of motion along the x and y axis.
</p>
<p><code>vel</code> is Q5.Vector, you can use any vector functions on it.</p>
<p>Restart this example to see the player sprite hit the block!</p>
</md>
Expand All @@ -476,7 +478,8 @@ <h2 id="sprite-movement">Sprite movement</h2>
</script>
<md id="md3-3">
<p>Yet, you may find it's more convenient to move a sprite by setting its <code>direction</code> and
<code>speed</code>.</p>
<code>speed</code>.
</p>
<p>You can also set a sprite's direction using an angle value or direction name such as: 'up', 'down',
'left', 'right', 'upLeft', 'upRight', 'downLeft', 'downRight'.</p>
</md>
Expand Down Expand Up @@ -853,7 +856,8 @@ <h2 id="sprite-rotation">Sprite rotation</h2>
</script>
<md id="md7-1">
<p>All of the other rotation methods on this page work by changing the sprite's
<code>rotationSpeed</code>.</p>
<code>rotationSpeed</code>.
</p>
</md>
<script type="mie/p5" id="rotationSpeed" base="5">
sprite.rotationSpeed = 1;
Expand Down Expand Up @@ -937,7 +941,7 @@ <h2 id="scaling">Scaling</h2>
new Canvas(500, 200);

sprite = new Sprite(250, 100, 90, 90);
sprite.img = 'assets/square.png';
sprite.img = 'assets/square.webp';
sprite.debug = true;
}

Expand Down Expand Up @@ -1500,7 +1504,8 @@ <h2 id="combo-sensors">Combo Sensors</h2>
<p>Overlap sensors determine if a sprite overlaps with another sprite.</p>
<p>By default when an overlap checking method is used, and the sprite has no sensors, the
<code>addDefaultSensors</code> function is used behind the scenes to create sensors for each of
the sprite's colliders.</p>
the sprite's colliders.
</p>
<p>You can add additional sensors to a sprite by using the <code>addSensor</code> function.</p>
</md>
</div>
Expand Down Expand Up @@ -1571,7 +1576,7 @@ <h2 id="custom-update">Custom Update</h2>
function setup() {
new Canvas(500, 200);

let face = loadImage('assets/face.png');
let face = loadImage('assets/face.webp');
let stretchy = new Sprite();

stretchy.draw = () => {
Expand Down Expand Up @@ -1662,8 +1667,8 @@ <h2 id="movement-sequencing">Movement Sequencing</h2>
repeatedly, without waiting for the sprite to reach its destination. But for better performance, try
using the <code>angleTo</code> function, which gets the angle between a sprite and a position. This
angle can be used to change the direction that the sprite moves in.</p>
<p>In this example, the q5 <a href="https://p5js.org/reference/p5/dist"
target="_blank"><code>dist</code></a> function is used to calculate the distance between the
<p>In this example, the q5 <a href="https://p5js.org/reference/p5/dist" target="_blank"><code>dist</code></a>
function is used to calculate the distance between the
player and its ally.</p>
</md>
<script type="mie/p5" base-8="" hidden="">
Expand Down Expand Up @@ -1721,16 +1726,16 @@ <h2 id="movement-sequencing">Movement Sequencing</h2>
</article>

<!-- <script src="https://cdn.jsdelivr.net/npm/p5@1/lib/p5.min.js"></script> -->
<script src="/v3/q5.min.js"></script>
<script src="/v3/planck.min.js"></script>
<script src="/v3/p5play.min.js"></script>
<script>
window.mie = { autoLoad: false };
<script src="/v3/q5.min.js"></script>
<script src="/v3/planck.min.js"></script>
<script src="/v3/p5play.min.js"></script>
<script>
window.mie = { autoLoad: false };

</script>
<script src="/learn/mie.js"></script>
<script src="/learn/learn.js"></script>
<script src="/account/account.js"></script>
<script src="/learn/learn.js"></script>
<script src="/account/account.js"></script>
</body>

</html>
1 change: 0 additions & 1 deletion learn/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ body.dark {

body.dark {
--pink0: oklch(0.657 0.294 16.698);
--pink1: oklch(0.657 0.294 16);
--pink1: oklch(0.6 0.28 16);
--pink2: oklch(0.11 0.28 16);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"version": "git add -A",
"postversion": "git push"
},
"version": "1.12.16"
"version": "1.13.0"
}
Loading

0 comments on commit cb0b10c

Please sign in to comment.