cocos2dx里面有两种坐标系,第一个是OpenGL坐标系,第二个是UIKit坐标系。
OpenGL坐标系是以左下角为原点(0,0),UIKit(界面坐标系)是以左上角为原点。
//坐标系和锚点 CCSprite *sprite = CCSprite::create("aladdin.png"); sprite->setPosition(ccp(0,0)); this->addChild(sprite); CCSprite *sprite1 = CCSprite::create("aladdin.png"); sprite1->setPosition(ccp(480,320)); sprite1->setAnchorPoint(ccp(1,1)); this->addChild(sprite1); CCPoint point = CCDirector::sharedDirector()->convertToUI(sprite1->getPosition()); CCLOG("x:%f,y:%f",point.x,point.y);
//相对坐标系 CCSprite *sp1 = CCSprite::create("icon.png"); sp1->setPosition(ccp(200,200)); this->addChild(sp1); CCSprite *sp2 = CCSprite::create("CloseNormal.png"); sp2->setPosition(ccp(0,0)); sp1->addChild(sp2);
//深度 CCSprite *sp1 = CCSprite::create("background.png"); sp1->setPosition(ccp(size.width*0.5,size.height*0.5)); this->addChild(sp1,1); CCSprite *sp2 = CCSprite::create("CloseNormal.png"); sp2->setPosition(ccp(90,90)); this->addChild(sp2,0); CCSprite *sp3 = CCSprite::create("CloseNormal.png"); sp3->setPosition(ccp(size.width-90,90)); this->addChild(sp3,2);
this->addChild(sp1,0,1);
欢迎关注我的围脖
==================== 迂者 丁小未 CSDN博客专栏=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
Unity QQ群:375151422 cocos2dx QQ群:280818155
====================== 相互学习,共同进步 ===================