Cocos2d: why convertToGL and why addChild CCSprite in front of your body?

I'm starting to learn cocos2d, and I was wondering why we actually use convertToGL from CCDirector, [[CCDirector sharedDirector] convertToGL: touchLoc]; when we already have [touch view] from [touch locationInView: [touch view]];

In addition, we first “addChild” CCSprite containing the image, and then set its body, and ccsprite becomes the data user of this body. Isn't the "addChild" body better? or is it for any specific purpose?

thanks

+7
source share
1 answer

This is because OpenGL View (class EAGLView) uses a different coordinate system than Cocoa Touch.

For example, the 0.0 position for Cocoa Touch is in the upper left corner, while the 0.0 position for OpenGL is in the lower left corner. This is why you need to "convert to GL" all UIView coordinates.

The conversion also takes into account the current orientation of the device.

+12
source

All Articles