Help with debugging the code for a student's game


My student is building a game similar to atari breakout. But he is having issue with bounciness of the ball when it collides with the blocks. I tried multiple things to change the velocity of it or change it to sprite.x and .y but nothing seems to work. Would appreciate any help.



I think the issue is with the use of collide instead of isTouching

From the collide help page.
"Makes each sprite in the group stop when it runs into the target. "

In the function blockBreak you may want to change those collides to isTouching and see what happens.


Hi Anisa,

I don’t know whether the student has changed the code since you posted, but I see a problem in that the function (blockBreak) that checks to see whether the ball is touching the block is called after the bounceOff is used in the draw loop. That means that the ball has already bounced off the blocks when you check to see whether it is touching. Instead of doing that, take the bounceOff calls out of the draw loop itself, and inside the blockBreak function, use bounceOff inside the conditional instead of isTouching, like this:

  if (breakoutBall.bounceOff(block)) {
    block.scale = 0;

bounceOff returns true or false according to whether it bounced off something, so this conditional will both bounce the ball off the block and runt he code inside the off statement if it did bounce off.



Thank you Elizabeth. This was helpful. It helped the student to fix part of the error.