I don’t know how to change the length of an object upon bouncing interaction in p5.play. In the code below, I wish to make the bar shorter from the top upon every hit, but don’t know what keyword to search for in the reference doc. Any suggestions?
var bals = [];
function setup() {
createCanvas(400, 400);
ball = createSprite(200, 10, 12, 12);
bar = createSprite(200, 300, 2, 100);
bar.immovable = true;
}
function draw() {
background(255);
if (frameCount % 120 == 0) {
bal = createSprite(200, 10, 12, 12);
bals.push(bal);
}
for (i = 0; i < bals.length; i++) {
bals[i].setSpeed(2, 90);
bals[i].bounce(bar, shortenBar);
}
drawSprites();
}
function shortenBar(ball, bar) {
ball.remove();
//make bar 10pixel shorter at the top upon each hit
}
Besides, how to make a sprite circular in shape as the default is square?
Thanks for your help!