draw a polygon with 8 points and use with physics:addBody.

I've searched the forums and understand that there are 3rd party solutions to this problem.

Is it possible to draw a polygon with 8 points in Corona, but without 3rd party tools, and if so, can I use physics:addBody with the resulting shape?

Thanks

Yes, you simply define the shape with a table of x,y coordinates in clockwise order, centered around 0,0. So a 20 pixel square shape would be defined like:

squareShape = {-10,-10,10,-10,10,10,-10,10}

8 points in the maximum, so your shape table would have 16 numbers, 2 for the x,y of each point. Since you're probably trying to fit the shape to an image it might be easier to load the graphic in Photoshop and turn the "info" panel on to find the correct coordinate spacing.

Then just apply that shape to the body:

physics.addBody( boxThing, "static", { density=1.6, friction=0.5, bounce=0.2, shape=squareShape } )

Some 3rd party tools let you trace an image and output the shape data, and some will create multiple shapes for objects with "complex bodies" (There are cases where 8 points is not enough, so you break the object up into multiple shapes that fit together and apply them all to the body).

Sure,you can do all that without a 3rd party tool, using graph paper and perhaps a calculator, but that can get time consuming and error prone if you have more than a couple simple shapes.

The easiest way to do this visually (if you don't want to pay for third party programs) is to download the adobe fireworks trial (it gives you 30 days free if memory serves me correctly) and grab the Physics shape panel for fireworks by ludicrous software here http://www.ludicroussoftware.com/corona-physics-shape-panel-for-fireworks/ (its free)

That way you can visually create your points and have the data you need exported for you ready to copy and paste into your code.

Hope this helps.

I use Physics Editor (http://www.physicseditor.de/) which is great for creating custom physics shapes. It's not free, but if you need to draw many custom physics shapes, it really is a bargain. I need hundreds of custom shapes and Physcis Editor has saved me weeks of development time.

views:1564 update:2011/10/11 15:24:38
corona forums © 2003-2011