Ball disappers from screen inspite of giving bounceoff(edges)

Hi,
i have the below code. Inspite of giving the bounceoff(edges) instruction to the ball, why is it that it disappers from the screen.

var ball= createSprite(200,200,10,10);
ball.velocityX=20;
ball.velocityY=20;

function draw() {
if(ball.x>400||ball.x<0||ball.y>400||ball.y<0)
{

}
background(“white”);
drawSprites();
createEdgeSprites();
ball.bounceOff(edges);

}

A little hard to tell without being able to test it myself. Can you perhaps click on the share link and share a link to your project rather than just pasting the code?

Off the top of my head, it appears that there is no code inside the conditional blocks right now and that the ball.bounceOff(edges) isn’t being triggered right when the ball leaves the screen. Also, another potential observation … the createEdgeSprites() would probably be more effective if done at the very beginning of the program … I could see a case where the ball is headed off the screen and then you catch it doing that, but by the time the createEdgeSprites command is executed, the ball is already well off the screen and can’t bounce …

Just a few things to look at, but share the link if you are still having some issues.

Good luck!

Mike

this is how the ball behaves, the ball.bounceoff(edges) is not getting triggered

The code for the above is very simple
var ball= createSprite(200,200,10,10);
ball.velocityX=20;
ball.velocityY=20;

function draw() {

background(‘white’);
createEdgeSprites();
ball.bounceOff(edges);
drawSprites();
}

You may have found a bug in the way the createEdgeSprites() and ball.bounceOff(edges) commands work. When I change your velocity to a speed lower than 15, it appears to work great. It bounces just fine and appears to do so indefinitely. However, at a higher velocity, the ball is somehow escaping the screen at the corners. This happens almost every time when the X and Y velocity are the same (as that causes it to perfectly hit the corner), but if you change one of them to a different number, such as 18 or 19, the ball bounces around the screen for a while, but any time there is a near direct hit on the corner, it escapes.

I don’t know exactly for for sure why, but I’m guessing the “edge sprites” that are created, although invisible, are thinner in the corner and at high velocities, the ball skips just enough pixels that it jumps over the border. Same thing happens when I remove the ball.velocityY command and set the ball.velocityX command to a high number (over 400). The ball skips over the edge and disappears from the screen.

If you need to use that high of a velocity in your program, you may manually have to create some sprites the top, bottom, left and right of your screen that are fairly tall and wide so the ball won’t skip over them or use a conditional block to check the x and y positions of the ball.

Let us know if we can help.

Mike