PHYSICS GURU: Can a display line be a static wall?

UPDATE: Figured it out for a line.

If I want to have the user draw a line so an object bounces off of it. Can a display LINE be added as a static physics body? The APIs states physics.addBody allows you to turn any Corona display object into a simulated physical object with one line of code, including the assignment of physical properties.

Assume for this post that there is only 1 line.

In this code fragment the line is displayed but physics objects just pass through. Here is the basic code fragment:

line = display.newLine( line1x, line1y, line2x, line2y );  
line:setColor( 255, 102, 102, 255 );  
line.width = 5;  
physics.addBody( line, "static", { density=20, friction=0.1, bounce=0.0 } );  

When I try to remove the line physics body I get this error:

physics.removeBody() given a display object that is not a physics object

physics.removeBody(line );  

Suggestions? [import]uid: 156018 topic_id: 35680 reply_id: 335680[/import]

I am curious how was this resolved? Can it be done with display.newLine? Or does it have to be rectangles? I have tried with rectangles and if user does fast swiping the rectangles become enlarged and distorts the physics. [import]uid: 75779 topic_id: 35680 reply_id: 141963[/import]

@rmckee282002 - It doesn’t have to be a rectangle, just use the shape parameter with the line endpoints. [import]uid: 156018 topic_id: 35680 reply_id: 141986[/import]

“Shape parameter with the line endpoints” Im sorry I dont understand what this means. Can you point me to some code? Are you using a drawing function similar to this one ?

http://developer.coronalabs.com/code/draw-line

If so I’ve tried to manipulate this code so that the line draw becomes a “static wall”, but I’m not sure what to do or if maybe I’m using the wrong line drawing function? Because I keep getting the “enlarged rectangle” effect. I’ve asked a few times on the forums and no one has ever been able to answer for me.
Thank you for the assistance! [import]uid: 75779 topic_id: 35680 reply_id: 142083[/import]

@rmckee282002

The drawing function you referenced does use the shape parameter (see the physics API) however it doesn’t create a line boundary but creates points as you move your mouse (simulator) or finger (device). Put the physics draw mode in debug and move the touch very fast and you will see gaps. If the gap is > ball diameter the ball falls through.

Creating a solid line with the start and end points is much easier and works great.

Again, read the APIs! [import]uid: 156018 topic_id: 35680 reply_id: 142132[/import]

@Lessmsios Yes you are correct thats what would happen with that!
So you are saying the drawing function above is no good?
Which API should I be looking at? Should I be using this one?
http://developer.coronalabs.com/content/displaynewline
thanks! [import]uid: 75779 topic_id: 35680 reply_id: 142229[/import]

Lessmos says
“Again, read the APIs!” is all you can say? [import]uid: 75779 topic_id: 35680 reply_id: 142702[/import]

I am curious how was this resolved? Can it be done with display.newLine? Or does it have to be rectangles? I have tried with rectangles and if user does fast swiping the rectangles become enlarged and distorts the physics. [import]uid: 75779 topic_id: 35680 reply_id: 141963[/import]

@rmckee282002 - It doesn’t have to be a rectangle, just use the shape parameter with the line endpoints. [import]uid: 156018 topic_id: 35680 reply_id: 141986[/import]

@russm305

The physics APIs. After considering my original post I re-read the physics APIs and experimented - and tada - easy. In it’s simplest form you put the 4 points of the line { Xstart, Ystart, Xend, Yend } into a table and pass that to the “shape” parameter. If you have multiple lines you simply loop through each line with the different X/Y points.

As the APIs state these points are relative to the center of the object (line in this case). [import]uid: 156018 topic_id: 35680 reply_id: 142777[/import]

“Shape parameter with the line endpoints” Im sorry I dont understand what this means. Can you point me to some code? Are you using a drawing function similar to this one ?

http://developer.coronalabs.com/code/draw-line

If so I’ve tried to manipulate this code so that the line draw becomes a “static wall”, but I’m not sure what to do or if maybe I’m using the wrong line drawing function? Because I keep getting the “enlarged rectangle” effect. I’ve asked a few times on the forums and no one has ever been able to answer for me.
Thank you for the assistance! [import]uid: 75779 topic_id: 35680 reply_id: 142083[/import]

@rmckee282002

The drawing function you referenced does use the shape parameter (see the physics API) however it doesn’t create a line boundary but creates points as you move your mouse (simulator) or finger (device). Put the physics draw mode in debug and move the touch very fast and you will see gaps. If the gap is > ball diameter the ball falls through.

Creating a solid line with the start and end points is much easier and works great.

Again, read the APIs! [import]uid: 156018 topic_id: 35680 reply_id: 142132[/import]

@Lessmsios Yes you are correct thats what would happen with that!
So you are saying the drawing function above is no good?
Which API should I be looking at? Should I be using this one?
http://developer.coronalabs.com/content/displaynewline
thanks! [import]uid: 75779 topic_id: 35680 reply_id: 142229[/import]

Lessmos says
“Again, read the APIs!” is all you can say? [import]uid: 75779 topic_id: 35680 reply_id: 142702[/import]

@russm305

The physics APIs. After considering my original post I re-read the physics APIs and experimented - and tada - easy. In it’s simplest form you put the 4 points of the line { Xstart, Ystart, Xend, Yend } into a table and pass that to the “shape” parameter. If you have multiple lines you simply loop through each line with the different X/Y points.

As the APIs state these points are relative to the center of the object (line in this case). [import]uid: 156018 topic_id: 35680 reply_id: 142777[/import]

Lessmos says
“Again, read the APIs!” is all you can say? [import]uid: 75779 topic_id: 35680 reply_id: 142702[/import]

@russm305

The physics APIs. After considering my original post I re-read the physics APIs and experimented - and tada - easy. In it’s simplest form you put the 4 points of the line { Xstart, Ystart, Xend, Yend } into a table and pass that to the “shape” parameter. If you have multiple lines you simply loop through each line with the different X/Y points.

As the APIs state these points are relative to the center of the object (line in this case). [import]uid: 156018 topic_id: 35680 reply_id: 142777[/import]

Lessmos says
“Again, read the APIs!” is all you can say? [import]uid: 75779 topic_id: 35680 reply_id: 142702[/import]

@russm305

The physics APIs. After considering my original post I re-read the physics APIs and experimented - and tada - easy. In it’s simplest form you put the 4 points of the line { Xstart, Ystart, Xend, Yend } into a table and pass that to the “shape” parameter. If you have multiple lines you simply loop through each line with the different X/Y points.

As the APIs state these points are relative to the center of the object (line in this case). [import]uid: 156018 topic_id: 35680 reply_id: 142777[/import]