Search code examples
iosios6cocos2d-iphonebox2d-iphone

Cocos2D 'fake' 3D projection on sprites. How to update Box2D bodies AND the debug draw to match.


I am using Cocos2D with the following settings: [director_ setProjection:kCCDirectorProjection3D]; in the appDelegate class
kmGLRotatef(-47, 1.0, 0, 0); in my layer's draw method
This ensures that my objects are presented in a simulated 3D environment.

I've added Box2D for collision detection. I've setup the bodies. When I enable the debug drawing, then the bodies are arranged on the whole screen and the sprites are arranged in a perspective.

How can I add the same perspective for the bodies too?


Solution

  • The advice given is to find a bounding box from the fake 3d transformation in cocos2d of the sprite. Then use this bounding box for both the body's debug drawing and also to determine the new (or transformed) body for box2d.