# How to change object size upon bouncing in p5.play

**URL:** https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540
**Category:** Libraries
**Created:** [December 21, 2019, 12:55am UTC](https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540 "2019-12-21T00:55:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![blkpanther](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@blkpanther](https://discourse.processing.org/u/blkpanther)
#### Post date: [December 21, 2019, 12:55am UTC](https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540/1 "2019-12-21T00:55:12Z")

</div>

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?

```auto
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!

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 21, 2019, 3:07am UTC](https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540/2 "2019-12-21T03:07:59Z")

</div>

hi, is the idea about  
HAMMER and NAIL ?

-a- that is a p5.js question, so better as posting code is  
to link to your  
[https://editor.p5js.org](https://editor.p5js.org)  
project

-b- you use createSprite?  
so it could have helped to say that  
you use a library  
[http://molleindustria.github.io/p5.play/](http://molleindustria.github.io/p5.play/) ;

-c- you make a NAIL and call it immovable,  
but actually you want it to move  
++ disable immovable  
++ make it heavy  
++ give it friction

-d- also why the NAIL should be round?  
but possible with using

```auto
    ball.draw = function() { ellipse(0,0,20,20) } 

```

example:  
[https://editor.p5js.org/kll/sketches/\_1NnYvVhB](https://editor.p5js.org/kll/sketches/_1NnYvVhB)

what adds also random HAMMER  
color and x position  
for fun

---

<div class="post-metadata">

### Author: ![blkpanther](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@blkpanther](https://discourse.processing.org/u/blkpanther)
#### Post date: [December 21, 2019, 3:30am UTC](https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540/3 "2019-12-21T03:30:47Z")

</div>

Thank you for your reply. Actually the bar isn’t a nail, and I need it to shorten upon each hit instead of moving down. Is there a way to do that?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 21, 2019, 3:37am UTC](https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540/4 "2019-12-21T03:37:13Z")

</div>

sorry, as i state in the example code i not know that library.

you could worst case use a  
`sprite.remove();`  
and make a new one on a lower position…  
but i know that is actually not the point, it is how to use the collision event?  
[https://molleindustria.github.io/p5.play/docs/classes/Sprite.html#method-bounce](https://molleindustria.github.io/p5.play/docs/classes/Sprite.html#method-bounce)  
!make your own bounce code

`sprite.height -=1;`  
could also work inthere

---

<div class="post-metadata">

### Author: ![blkpanther](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@blkpanther](https://discourse.processing.org/u/blkpanther)
#### Post date: [December 21, 2019, 4:34am UTC](https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540/5 "2019-12-21T04:34:17Z")

</div>

Thanks! You pointed me to the right direction. Adjusting height and y position will solve the problem.
