For i = 0 To Maps.Layers.Get2("ObjTest").Objects.GetAllObjects.Size -1
Log("NUmber of Objects on MAP:" & Maps.Layers.Get2("ObjTest").Objects.GetAllObjects.Size)
Dim bd As lgBox2DBodyDef
bd.Type = world.BODYTYPE_Static
bd.allowSleep = True
bd.awake = True
Dim MapObj As lgMapObject = Maps.Layers.Get2("ObjTest").Objects.Get(i)
'Log("Keys" & MapObj.Properties.GetAllKeys)
'Log("Values" & MapObj.Properties.GetAllValues)
Select MapObj.Properties.Get("type")
Case "lgMapPolylineMapObject" 'this is the actual ground cq SCENERY
Dim Obj As lgMapPolylineMapObject = Maps.Layers.Get2("ObjTest").Objects.Get(i)
'retrieve polyline and scale the vertexes including position.
Obj.Polyline.setPosition(Obj.Polyline.X*(scale), Obj.Polyline.y*(scale))
Obj.Polyline.setScale(scale, scale)
'create shape and use the transformed vertices as we scaled it.
Dim eshape As lgBox2DChainShape
eshape.createChain(Obj.Polyline.TransformedVertices)
'Log("Bodyground position" & WorldGround.Polyline.X & " - " & bd.position.y)
'now we have the fixture
Dim fd As lgBox2DFixtureDef
fd.shape = eshape
fd.restitution = 0
fd.friction = 0.25
fd.filter.categoryBits = Main.CATEGORY_SCENERY
fd.filter.maskBits = Main.MASK_SCENERY
fd.filter.groupIndex = 1
'give it to the world, baby!
bdyGround = world.CreateBody(bd)
bdyGround.createFixture(fd)
GroundList.Add(bdyGround)
eshape.Dispose
Case "lgMapEllipseMapObject"
Dim ObjCircle As lgMapEllipseMapObject = Maps.Layers.Get2("ObjTest").Objects.Get(i)
'ObjCircle.Ellipse.Set(ObjCircle.Ellipse.x*scale,ObjCircle.Ellipse.y*scale,ObjCircle.Ellipse.width*scale, ObjCircle.Ellipse.height*scale)
Log("Object Circle: X-" & ObjCircle.Ellipse.x & " - Y: " & ObjCircle.Ellipse.y)
Dim V As lgMathVector2
V.Set(ObjCircle.Ellipse.x*scale, ObjCircle.Ellipse.y*scale)
Log("Vector: " & V)
Dim CircleShape As lgBox2DCircleShape
CircleShape.Radius = (ObjCircle.Ellipse.height/2)*scale
CircleShape.Position.Set(0,0)
' CircleShape.Position.x = ObjCircle.Ellipse.x*scale
' CircleShape.Position.y = ObjCircle.Ellipse.y*scale
' Log("Scale=" & scale & " Shape Circle: X-" & CircleShape.Position.x & " - Y: " & CircleShape.Position.y)
'now we have the fixture
Dim fd As lgBox2DFixtureDef
fd.shape = CircleShape
fd.restitution = 0.5
fd.friction = 0.25
fd.filter.categoryBits = Main.CATEGORY_OBJECT
fd.filter.maskBits = Main.MASK_OBJECT
fd.filter.groupIndex = 1
Log("Filter Ellips" & fd.filter.categoryBits & "-" & fd.filter.maskBits & "-" & fd.filter.groupIndex)
Dim WorldObject As lgBox2DBody
'set the body def position
bd.position.Set(ObjCircle.Ellipse.x*scale,ObjCircle.Ellipse.y*scale)
'give it to the world, baby!
WorldObject = world.CreateBody(bd)
WorldObject.createFixture(fd)
Log("WorldObject: " & (WorldObject.Position) )
GroundList.Add(WorldObject)
CircleShape.Dispose
Case "lgMapRectangleMapObject"
'retreive the rectangle from the map.
Dim ObjRectangle As lgMapRectangleMapObject = Maps.Layers.Get2("ObjTest").Objects.Get(i)
ObjRectangle.Rectangle.setPosition2(ObjRectangle.Rectangle.x*scale,ObjRectangle.Rectangle.y*scale)
'convert to a polygonshape
Dim RectangleShape As lgBox2DPolygonShape
Dim V As lgMathVector2
V.Set((ObjRectangle.Rectangle.width/2)*scale, (ObjRectangle.Rectangle.height/2)*scale)
RectangleShape.SetAsBox2((ObjRectangle.Rectangle.width*scale)/2, (ObjRectangle.Rectangle.height*scale)/2, V,0)
'Start creating the body
Dim WorldObject As lgBox2DBody
'now we have the fixture
Dim fd As lgBox2DFixtureDef
fd.shape = RectangleShape
fd.restitution = 0.5
fd.friction = 0.25
fd.filter.categoryBits = Main.CATEGORY_OBJECT
fd.filter.maskBits = Main.MASK_OBJECT
fd.filter.groupIndex = 1
bd.position.Set(ObjRectangle.Rectangle.x, ObjRectangle.Rectangle.y)
'give it to the world, baby!
WorldObject = world.CreateBody(bd)
WorldObject.createFixture(fd)
GroundList.Add(WorldObject)
RectangleShape.Dispose
Case Else
Log("MapObjects found which have unknown type!")
End Select
Next