本文整理汇总了C++中CCControlButton::setAnchorPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ CCControlButton::setAnchorPoint方法的具体用法?C++ CCControlButton::setAnchorPoint怎么用?C++ CCControlButton::setAnchorPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCControlButton
的用法示例。
在下文中一共展示了CCControlButton::setAnchorPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: displaySubViews
void QuestionLayer::displaySubViews()
{
CCLOG("%f %f %f %f", this->getPositionX(), this->getPositionY(), this->getContentSize().width, this->getContentSize().height);
CCArray* answer = questionObj->answerArray;
int columns = 0;
int rows = 0;
float spaceX = 0;
if (answer->count() <= 2) {
//判断题2X1个
columns = 2;
rows = 1;
spaceX = 80;
} else if (answer->count() <= 3) {
//3选1
columns = 1;
rows = 3;
spaceX = 40;
} else if (answer->count() <= 4) {
//最多2x2个答案选项的
columns = 2;
rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns);
spaceX = 60;
} else if (answer->count() <= 9) {
//最多3x3个答案选项
columns = 3;
rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns);
spaceX = 40;
} else if (answer->count() <= 16) {
//最多4x4个答案选项
columns = 4;
rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns);
spaceX = 20;
}
float spaceY = spaceX*(CCDirector::sharedDirector()->getWinSize().height/1334);
//题目标题栏高度
float topHeight = 190;
CCLOG("%f %f", this->getContentSize().width, this->getContentSize().height);
//
float totalWidth = this->getContentSize().width;
float cellWidth = (totalWidth-spaceX*(columns+1))/columns;
float totalHeight = this->getContentSize().height-topHeight-50; //要减去答题头部区域
float cellHeight = (totalHeight-spaceY*(rows+1))/rows;
CCLOG("[%d %d]:%f %f", columns, rows, cellWidth, cellHeight);
while (cellHeight > cellWidth) {
spaceY += 10;
cellHeight = (totalHeight-spaceY*(rows+1))/rows;
}
for (int i=0; i<answer->count(); i++) {
//
CCString* ans = (CCString *)(answer->objectAtIndex(i));
CCLabelTTF* pLabel = CCLabelTTF::create(ans->getCString(), "Arial", 24, CCSizeMake(cellWidth, cellHeight), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
CCControlButton* button = CCControlButton::create(pLabel, CCScale9Sprite::create("button_answer.png", CCRectMake(0, 0, 126, 70)));
button->addTargetWithActionForControlEvents(this, cccontrol_selector(QuestionLayer::touchDownAction), CCControlEventTouchUpInside);
button->setTag(i+1);
button->setAnchorPoint(ccp(0.5f, 0.5f));
// button->setPosition( ccp(-totalWidth/2+spaceX+(cellWidth+spaceX)*(i%columns)+cellWidth/2, -topHeight/2-totalHeight/2+spaceY+(cellHeight+spaceY)*(i/columns)+cellHeight/2) );
button->setPosition( ccp(-totalWidth/2+spaceX+(cellWidth+spaceX)*(i%columns)+cellWidth/2, (totalHeight-topHeight)/2-spaceY-(cellHeight+spaceY)*(i/columns)-cellHeight/2) );
CCLOG("button坐标:%f %f", button->getPositionX(), button->getPositionY());
button->setPreferredSize(CCSize(cellWidth, cellHeight));
this->addChild(button, 1);
}
}
示例2: init
bool CPullMachHelpLayer::init()
{
if (!CCLayer::init())
return false;
CCSize barDownSize; //µ×Ãæ±ß¿ò³ß´ç
CCSize barUpSize; //ÉÏÃæ±ß¿ò³ß´ç
CCSize infoBgSize; //ÐÅÏ¢±³¾°³ß´ç
CCSize infoViewSize; //ÐÅÏ¢¿ÉÊӳߴç
CCSprite * pSprite = NULL;
if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Down, pSprite))
{
barDownSize = pSprite->getContentSize();
pSprite->setAnchorPoint(CCPointZero);
pSprite->setPosition(CCPointZero);
this->addChild(pSprite);
}
{
float fHeight = this->getContentSize().height - 200;
infoBgSize.setSize(barDownSize.width, (fHeight > 600) ? 600 : fHeight);
CCLayerColor * bgLayer = CCLayerColor::create(ccc4(0, 24, 85, 255), infoBgSize.width, infoBgSize.height);
bgLayer->setPosition(ccp(0, barDownSize.height));
this->addChild(bgLayer);
}
if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Up, pSprite))
{
barUpSize = pSprite->getContentSize();
pSprite->setAnchorPoint(CCPointZero);
pSprite->setPosition(ccp(0, barDownSize.height + infoBgSize.height));
this->addChild(pSprite);
}
//Ìí¼Ó¹ö¶¯ÄÚÈÝ
infoViewSize.setSize(infoBgSize.width - 20, infoBgSize.height);
if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Info, pSprite))
{
pSprite->setAnchorPoint(ccp(0.5f, 0.0f));
pSprite->setPosition(ccp(infoViewSize.width / 2, 0));
}
CCLayerColor * layerColor = CCLayerColor::create(ccc4(0, 13, 32, 255), infoViewSize.width, pSprite->getContentSize().height);
layerColor->setPosition(CCPointZero);
layerColor->addChild(pSprite);
m_pScroll = CCScrollView::create();
m_pScroll->setViewSize(infoViewSize);
m_pScroll->setPosition(ccp(10, barDownSize.height));
m_pScroll->setDirection(kCCScrollViewDirectionVertical);
m_pScroll->addChild(layerColor);
m_pScroll->setContentSize(layerColor->getContentSize());
m_pScroll->setContentOffset(m_pScroll->minContainerOffset());
m_pScroll->setTouchPriority(kCCMenuHandlerPriority - 1);
this->addChild(m_pScroll);
this->setContentSize(CCSize(infoBgSize.width, barDownSize.height + barUpSize.height + infoBgSize.height));
//Ìí¼Ó¹Ø±Õ°´Å¥
CCControlButton* pCloseButton = m_pResManager->CreateControlButton(PullMach_Bt_Help_Close_N, PullMach_Bt_Help_Close_C);
pCloseButton->setAnchorPoint(ccp(1, 1));
pCloseButton->setPosition(getContentSize().width - 10, getContentSize().height - 4);
pCloseButton->addTargetWithActionForControlEvents(this, cccontrol_selector(CPullMachHelpLayer::OnTouchClose), CCControlEventTouchUpInside);
pCloseButton->setScaleX(1.5f);
this->addChild(pCloseButton);
return true;
}