7

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

Paul
  • 6,108
  • 14
  • 72
  • 128
  • only one question please, unless the other/followup question is related to the main question – CodeSmile Nov 04 '11 at 17:38
  • 1
    second part: I suppose you mean a Box2D body. The addChild method only takes objects derived from CCNode. It doesn't know how to work with the b2Body class. – CodeSmile Nov 04 '11 at 17:39
  • @LearnCocos2D : okay thanks for the quick answer! and sorry for the double question, i'll keep it in mind! – Paul Nov 04 '11 at 20:23

1 Answers1

12

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217