b2Body* HelloWorld::addNewSpriteWithCoords(CCPoint p,string nname,int tag) { string name = nname; CCSprite* sprite = CCSprite::create((name+".png").c_str()); sprite->setPosition(p); sprite->setTag(tag); bgLayer->addChild(sprite); b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO); bodyDef.userData = sprite; b2Body *body = world->CreateBody(&bodyDef); // add the fixture definitions to the body GB2ShapeCache *sc = GB2ShapeCache::sharedGB2ShapeCache(); sc->addFixturesToBody(body, name.c_str()); sprite->setAnchorPoint(sc->anchorPointForShape(name.c_str())); return body; }