Flipped Y in Cocos2d-x 2

Flipped Y in Cocos2d-x 2
0.0 0


Hi all,

I just switched to cocos2d-x 2 for a new project so i took the one from git.

I was wondering, when I place a sprite at the screen like 0,0 it is at the bottom corner ?
Origin was top left right?
But when i log the ccTouch it is correct, 0,0 is at top left, but my sprite is at bottom left.
Is this a bug?

friendly regards,



If you want placed your sprite in position(0, 0) you can use two method:

yourSprite->setAnchorPoint(0, 0);
yourSprite->setPosition(ccp(0, 0); 


CCSize spriteSize = yourSprite->getContentSize();
yourSprite->setPosition(spriteSize.width/2, spriteSize.height/2);

Read this for understanding - http://www.qcmat.com/understanding-anchorpoint-in-cocos2d/


Thats not what I mean :stuck_out_tongue:

I mean the origin of the view is top left of the screen.
so X = 0 and Y = 0 then it is top left of the screen.
And when I log my touches they print the correct position.
Top is 0 and bottom is 480.
But my sprite draw inversed. So when i change position of sprite to 0,480 it is drawed at the top of the screen instead of the bottom. =/



Oh, sorry :slight_smile:
Use that:

CCPoint touchPoint = CCDirector::sharedDirector()->convertToGL(pTouch->locationInView());

I think that snippet may help you:

void YourClass::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) {
  mSprite->setPosition(CCDirector::sharedDirector()->convertToGL(pTouch->locationInView()) );

In cocos origin using like openGL.


TY ! Damn how could i be so stupid .
I just did pTouch->getLocationInView()
instead of CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());