Got this working now, just had another look at it, was my silly mistake with the xpos. For those interested this is my code I've wrote to parse SVG and create static body.
This is my quicky SVG file parser code (called from init method):
NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"cakemap.svg"];
NSData *XMLData = [NSData dataWithContentsOfFile:XMLPath];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
NSArray *nodes = NULL;
NSArray *bodyArray = NULL;
nodes = [doc nodesForXPath:@"//svg[@height]" error:nil];
CXMLElement *nd = (CXMLElement*)[nodes objectAtIndex:0];
NSString *mheight = [[nd attributeForName:@"height"] stringValue];
float mapHeight = [mheight floatValue];
bodyArray = [doc nodesForXPath:@"//rect" error:nil];
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
CGPoint posy;
CGPoint sz;
for (CXMLElement *node in bodyArray)
{
NSString *swidth = [[node attributeForName:@"width"] stringValue];
float width = [swidth floatValue];
NSString *sheight = [[node attributeForName:@"height"] stringValue];
float height = [sheight floatValue];
NSString *sx = [[node attributeForName:@"x"] stringValue];
float xpos = [sx floatValue];
NSString *sy = [[node attributeForName:@"y"] stringValue];
float ypos = [sy floatValue];
nCount++;
posy = ccp(xpos, mapHeight - ypos);
sz = ccp(width/2, height/2);
b2Fixture *pFixture = [self addStaticPlatformBodyWithCoords:posy size:sz];
// code that follows creates objects of fixtures
}
And my code to add a static body:
-(b2Fixture*)addStaticPlatformBodyWithCoords:(CGPoint)p size:(CGPoint)w
{
b2BodyDef bodyDef;
bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
b2Body *body = world->CreateBody(&bodyDef);
b2PolygonShape staticBox;
staticBox.SetAsBox(w.x/PTM_RATIO, w.y/PTM_RATIO, b2Vec2(w.x /PTM_RATIO,-w.y/PTM_RATIO), 0);
b2FixtureDef fixtureDef;
fixtureDef.shape = &staticBox;
return body->CreateFixture(&fixtureDef);
}
My SVG file I parse doesn't contain any details about friction, density etc, this is a still to do.
Regards,
Steve