这两天看了下锚点的概念。
/**
* Sets the anchor point in percent.
*
* anchorPoint is the point around which all transformations and positioning manipulations take place.
* It's like a pin in the node where it is "attached" to its parent.
* The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
* But you can use values higher than (1,1) and lower than (0,0) too.
* The default anchorPoint is (0.5,0.5), so it starts in the center of the node.
*
* @param anchorPoint The anchor point of node.
*/
virtual void setAnchorPoint(const CCPoint& anchorPoint);
anchorPoint is the point around which all transformations and positioning manipulations take place.
是为了在定位位置和翻转的时候用的参考点。
CCSprite* sprite5 = CCSprite::create("CloseNormal.png");
sprite5->setAnchorPoint( ccp(0.5,0.5) );
sprite5->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
this->addChild(sprite5);
此时 (ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2)) 点正在sprite5的中心点( ccp(0.5,0.5))
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
// 右上角
CCSprite* sprite1 = CCSprite::create("CloseSelected1.png");
sprite1->setAnchorPoint( ccp(0,0) );
sprite1->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
this->addChild(sprite1);
// 左上角
CCSprite* sprite2 = CCSprite::create("CloseNormal.png");
sprite2->setAnchorPoint( ccp(1,0) );
sprite2->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
this->addChild(sprite2);
// 左下角
CCSprite* sprite3 = CCSprite::create("CloseNormal.png");
sprite3->setAnchorPoint( ccp(1,1) );
sprite3->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
this->addChild(sprite3);
// 右下角
CCSprite* sprite4 = CCSprite::create("CloseNormal.png");
sprite4->setAnchorPoint( ccp(0,1) );
sprite4->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
this->addChild(sprite4);
// 中间
CCSprite* sprite5 = CCSprite::create("CloseNormal.png");
sprite5->setAnchorPoint( ccp(0.5,0.5) );
sprite5->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
this->addChild(sprite5);