Creating Shapes - for images and AddBody - Need this expained

Documentation Example:

shape
number: Shape value in the form of a table with the shape vertices, {x1,y1,x2,y2,…,xn,yn}. For example: squareShape = { -20,-10, 20,-10, 20,10, -20,10 }

Question 1:
This does not explain how the shaped is matched on an image. This is confusing to me, I dont understand how you can have -20 and -10 in the shape declaration unless you are using the X position in the middle of the image. If so what about other shape types like this pentagon Shape

pentagonShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }

how do these mappings work in corona? Can someone please let us know, there really needs to be more documentation on this.

Question 2:
Anybody know of a tool that will do this for your shapes automatically for complex shapes?

If this is explained more in the documentation i could not find it.

Thanks Larry
[import]uid: 11860 topic_id: 4489 reply_id: 304489[/import]

The reason for this question is that I have a platform that moves back and forth across the screen, and the X collision never occurs until the middle of the object actually hits the wall on both sides.

here is my code for creating the platform

local platform = display.newImage( "platform1.png" )  
platform.x = 50; platform.y = 150  
physics.addBody( platform, "kinematic", { friction=0.7 } )  
local platformShape = { -50,-20, 50,-20, -50,20,50,20 }  
physics.addBody( platform, "kinematic", { bounce=0, friction=0.7, shape=platformShape } )   
  
local function onPlatformCollision(event )  
 t:setText( "onPlatformCollision-" .. event.object1.x );  
 transition.cancel(platformSlide)  
 if (event.object1.x \<= 0) then xdirection = 5 end  
 if (event.object1.x \>= display.contentWidth) then xdirection = -5 end  
  
 platformSlide = transition.to( platform, { time=50, x=platform.x + xdirection, onComplete=movePlatform })  
  
end  
  
local platformSlide  
local xdirection = 5  
  
local function movePlatform (self, event)  
  
t:setText( "movePlatform-" .. platform.x .. "-" .. display.contentWidth );  
  
if (platform.x \<= 0) then xdirection = 5 end  
if (platform.x \>= display.contentWidth) then xdirection = -5 end  
platformSlide = transition.to( platform, { time=50, x=platform.x + xdirection, onComplete=movePlatform })  
  
end  

Anyone have a clue on this one? [import]uid: 11860 topic_id: 4489 reply_id: 14070[/import]

The shape’s origin is in the center so a table reference for a square that is 20px wide (please note you wouldn’t need this for a square but whatever) would look like:

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

as it says in the docs it is basically a series of Points, although somewhat confusingly all laid out flat in the table (array).

The order is clockwise so you would trace around the shape starting at the top left and circling your way around. This post helped me tremendously:

http://developer.anscamobile.com/forum/2010/11/03/physics-complex-polygon-tool

I’m using the Flash exporter tool (http://www.box2d.org/forum/viewtopic.php?f=8&t=463) to take a vector shape and have it pump out an array. Doing a slight bit of manual parsing and everything seems to work out ok. Setting physics mode to hybrid also helps a lot to see what the shapes are doing and what they look like laid over your graphics.

Hope this helps! [import]uid: 11554 topic_id: 4489 reply_id: 14214[/import]