Bodies and sprites not aligning

Hello,

I have a Cocos2d Sprite and a Box2d Body. I am using a PTM_Ratio of 32.

On a standard iPhone device (480 x 680) my sprite is at position 240 x 300 and the b2body at 7.5 x 9.375. The body and sprite match up perfectly. The sprite and box2d body also appear in the correct location.

On a retinar display iPhone device (960 x 320) my sprite is at position 480 x 600 and the b2body at 15 x 18.75. The b2Body appears in the correct place but the sprite is nowhere near, it is around 200 pixels away.
I have tried everything from changing the PTM ratio to 16 and 64 (as it's double the size in retinar) to removing the sprite position. None of these work.

Update: I have just noticed the bodies appear weird such as overlapping in the higher resolution. I assume it has something to do with the PTM.

What on earth am I doing wrong?
I have found the solution to this encase anyone else if having the same issue.

It appears to be a common fault with box2d not scaling to the retinar display. The resolution and sprites are managed by Cocos2d but box2d appears to get left behind working in standard 480x320 mode.

To scale box2d add this in your draw method.

Code: Select all

   
glPushMatrix();
glScalef(CC_CONTENT_SCALE_FACTOR(), CC_CONTENT_SCALE_FACTOR(), 1.0f);
world->DrawDebugData();
glPopMatrix();


This will scale box2d objects by 2 for HD and 1 by default.

You may find the physics act weird in the simulator but I found once I compiled to a device it works as expected.

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