How to keep my bouncing object in the screen?

Hi Guys,

I am in learing stage of Corona. I created a ball that will fall from up to bottom and hit some other objects, but it will go off the screen after several bounces. How can I keep it in the screen?  So I want it to hit the edge of the screen and bounce back again and again and never leave the screen?

Thank you so much, I know this might be so easy and the most basics questions for phycis engines for some of you guys  :slight_smile:

Andy

You have to setup walls for the balls to bounce off of.  The wall can be just off screen to keep it from showing.  The walls would be a display.newRect() that has a static physics body attached to it.

Rob

Thank you Rob. That makes sense. So I need to create 2 walls, one for left, one for right. Is this the only way to do that? or there are other alternative options?

Andy

There would be other alternate ways, but this is by far the simplest and best way.  Other methods end up fighting the physics engine.

Rob

You have to setup walls for the balls to bounce off of.  The wall can be just off screen to keep it from showing.  The walls would be a display.newRect() that has a static physics body attached to it.

Rob

Thank you Rob. That makes sense. So I need to create 2 walls, one for left, one for right. Is this the only way to do that? or there are other alternative options?

Andy

There would be other alternate ways, but this is by far the simplest and best way.  Other methods end up fighting the physics engine.

Rob