Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cocos2d : why convertToGL, and why addChild CCSprite before its body?

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

Also, we first "addChild" a CCSprite, containing an image, and then we set its body, and the ccsprite becomes the data user of this body. Would'nt it better to "addChild" the body instead? or is it for any particular purpose?

Thanks

like image 350
Paul Avatar asked Nov 04 '11 15:11

Paul


1 Answers

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

For example, the 0,0 position for Cocoa Touch is on the upper left corner, whereas the 0,0 position for OpenGL is in the lower left corner. That's why you need to "convert to GL" all UIView coordinates.

The conversion also takes into account the current device orientation.

like image 158
LearnCocos2D Avatar answered Oct 22 '22 00:10

LearnCocos2D