Moving/Panning the b2World

Hi,

I've looked through the forums and know there is some topics on this kind of thing already, but I'm finding them very confusing.

I'm trying to pan across my world by touch and drag (the b2World layer being bigger than the screen), much like you would pan/move around in say google maps.

So far I have understood that you can move the camera or move the layer (which I think means moving all the sprites/bodies etc.)

I can get the camera movement working in the following way:

//In ccTouchesMoved:
[self.camera setEyeX:touchPosition.x eyeY:touchPosition.y eyeZ:1];
[self.camera setCenterX:touchPosition.x centerY:touchPosition.y centerZ:0];
//Where touchPosition is a CGPoint and the difference between the previous touch point and the current touch point

Alternatively, I can get the sprites to move in the following way:
//In ccTouchesMoved:
self.position = touchPosition;

However, with both of these, the sprites' bodies stay in their original place, ie. the sprite images are moving but not the bodies which the images are attached to. I expected this with the latter option, but not with the first. I guess moving the camera has no affect on the bodies as it's nothing to do with box2d.

So, as far as I can see from this and forum topics I need to run through all the bodies and update their positions. But I can't get this to work:

//In ccTouchesMoved:
PTM_RATIO = 32;
b2Vec2 pos;
for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
if (b->GetUserData() != NULL) {
CCSprite *sprite = (CCSprite *)b->GetUserData();
pos = ccp(sprite.position.x/PTM_RATIO, sprite.position.y/PTM_RATIO);
b->SetTransform(pos, 0.0f);
}
}

The body positions don't change. Could anyone help point me in the right direction?
Thanks in advance...

Additional note:
I've also noticed that the edgeBody I am creating for the screen edges is moving along with sprite images, but the the spriteBody stay still.
I'm guessing it might have something to do with the way i am creating a sprite and body and the way i'm creating my edgeBody.

I have the following to create my edge body:
-(id) init {
if( (self=[super init])) {
CGSize winSize = [CCDirector sharedDirector].winSize;
self.isTouchEnabled = YES;

b2Vec2 gravity = b2Vec2(0.0f, 0.0f);
bool doSleep = true;
_world = new b2World(gravity, doSleep);

b2BodyDef groundBodyDef;

groundBodyDef.position.Set(0,0);

groundBody = _world->CreateBody(&groundBodyDef);

b2PolygonShape groundBox;

b2FixtureDef groundBoxDef;

groundBoxDef.shape = &groundBox;
// Base
groundBox.SetAsEdge(b2Vec2(-50/PTM_RATIO,-50/PTM_RATIO), b2Vec2(winSize.width/PTM_RATIO+50/PTM_RATIO, -50/PTM_RATIO));
bottomFixture = groundBody->CreateFixture(&groundBoxDef);

//Left
groundBox.SetAsEdge(b2Vec2(-50/PTM_RATIO,-50/PTM_RATIO), b2Vec2(-50/PTM_RATIO, winSize.height/PTM_RATIO+50/PTM_RATIO));
groundBody->CreateFixture(&groundBoxDef);

// Top
groundBox.SetAsEdge(b2Vec2(-50/PTM_RATIO, winSize.height/PTM_RATIO+50/PTM_RATIO), b2Vec2(winSize.width/PTM_RATIO+50/PTM_RATIO, winSize.height/PTM_RATIO+50/PTM_RATIO));
groundBody->CreateFixture(&groundBoxDef);

// Right
groundBox.SetAsEdge(b2Vec2(winSize.width/PTM_RATIO+50/PTM_RATIO, winSize.height/PTM_RATIO+50/PTM_RATIO), b2Vec2(winSize.width/PTM_RATIO+50/PTM_RATIO, -50/PTM_RATIO));
groundBody->CreateFixture(&groundBoxDef);

//And to create my sprite

gameLayer = [[CCLayer alloc] init];

[self addChild:gameLayer z:2];

ball = [CCSprite spriteWithFile:@"ball.png" rect:CGRectMake(0, 0, 200, 200)];

ball.position = ccp(180, 290);
[gameLayer addChild:ball];
ball.tag = 1;
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(180/PTM_RATIO, 290/PTM_RATIO);
ballBodyDef.userData = ball;
ballBody = _world->CreateBody(&ballBodyDef);
b2CircleShape ballShape;
ballShape.m_radius = 23.0/PTM_RATIO;

b2FixtureDef ballShapeDef;
ballShapeDef.shape = &ballShape;
ballShapeDef.density = 1.0f;
ballShapeDef.friction = 0.0f;
ballShapeDef.restitution = 1.0f;
ballFixture = ballBody->CreateFixture(&ballShapeDef);
}
return self;
}

So, I can get everything to move that I want to move, except the ball's body. I know this because if I move everything, to then push the ball (with a user's touch) I have to click on the space where the ball was initialized and not where the ball's image has moved to. And I know the edges move with the move because the ball bounces off the invisible edge at different places as i move everything around.

Any help would be much appreciated. Thanks.....

Update 2.
Ok, my edges aren't moving, I don't think. Its the boundary of the layer that the ball sprite is in that im moving that changes where the ball bounces off.

Basically I can't update the position of bodies as I move a layer which my sprite images are on so that the bodies move inline with their images.

Original thread: https://box2d.org/forum/viewtopic.php?t=5830