I am trying to get my box2d game to work in retina mode, and I am facing a lot of annoying problems when working in higher resolution mode.
cocos2d correctly displays my graphics in retina mode, but I found that hacking after hacking was necessary to make box2d work the same way as in lower resolution mode. For example, I find that I need to do something similar to get the correct size of the debug form in retina mode:
b2Vec2 vertices[4]; vertices[0].Set(-0.5f / CC_CONTENT_SCALE_FACTOR(), 1.0f / CC_CONTENT_SCALE_FACTOR()); vertices[1].Set(-0.5f / CC_CONTENT_SCALE_FACTOR(), -1.0f / CC_CONTENT_SCALE_FACTOR()); vertices[2].Set(0.5f / CC_CONTENT_SCALE_FACTOR(), -1.0f / CC_CONTENT_SCALE_FACTOR()); vertices[3].Set(0.5f / CC_CONTENT_SCALE_FACTOR(), 1.0f / CC_CONTENT_SCALE_FACTOR()); int32 count = 4; b2PolygonShape polygon; polygon.Set(vertices, count);
This hack (setting all vertex points to CC_CONTENT_SCALE_FACTOR() ), of course, inevitably leads to a density hack so that the movement looks like a lower resolution mode:
b2FixtureDef fixtureDef; fixtureDef.shape = &polygon; fixtureDef.density = 1.0f * CC_CONTENT_SCALE_FACTOR(); fixtureDef.friction = 0.9f; playerBody->CreateFixture(&fixtureDef);
And this leads to another hack of settings when applying forces:
b2Vec2 force = b2Vec2(10.0f / CC_CONTENT_SCALE_FACTOR(), 15.0f / CC_CONTENT_SCALE_FACTOR()); playerBody->ApplyLinearImpulse(force, playerBody->GetPosition());
Keep in mind that I draw in debug mode, scaling my draw debug calls, for example:
glPushMatrix(); glScalef(CC_CONTENT_SCALE_FACTOR(), CC_CONTENT_SCALE_FACTOR(), 1.0f); world->DrawDebugData(); glPopMatrix();
What am I fundamentally misunderstanding about how box2d works with retina mode? I use the Steffen Itterheim Box2DHelper class instead of PTM_RATIO , but it just doesn't seem to be enough. Any ideas? At the moment, I'm going to completely abandon the retina mode for my game.