本文整理汇总了C++中CCLabelTTF::setScaleY方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLabelTTF::setScaleY方法的具体用法?C++ CCLabelTTF::setScaleY怎么用?C++ CCLabelTTF::setScaleY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLabelTTF
的用法示例。
在下文中一共展示了CCLabelTTF::setScaleY方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLabel
CCLabelTTF* GXLabelTTFCreator::getLabel() {
if (content != NULL) {
CCLabelTTF* label = NULL;
if(relativeDWidthType == relativeDWidthZeroType) {
label = CCLabelTTF::create(content->getCString(),"Arial",size,CCSizeMake(dimensionsWidth,dimensionsHeight),textAlignment,verticalAlignment);
} else if(relativeDWidthType == relativeDWidthCenterType) {
label = CCLabelTTF::create(content->getCString(),"Arial",size,CCSizeMake(winSize.width/2 + dimensionsWidth, dimensionsHeight),textAlignment,verticalAlignment);
} else if(relativeDWidthType == relativeDWidthWidthType) {
label = CCLabelTTF::create(content->getCString(),"Arial",size,CCSizeMake(winSize.width + dimensionsWidth, dimensionsHeight),textAlignment,verticalAlignment);
}
if (relativeType == relativeZeroType) {
label->setPosition(ccp(x,y));
} else if(relativeType == relativeCenterType) {
label->setPosition(ccp(winSize.width/2+x,y));
} else if(relativeType == relativeWidthType) {
label->setPosition(ccp(winSize.width+x,y));
}
label->setScaleX(scaleX);
label->setScaleY(scaleY);
label->setAnchorPoint(ccp(anchorX,anchorY));
label->setColor(ccc3(r,g,b));
label->setOpacity(a);
label->_setZOrder(zOrder);
return label;
}
return NULL;
}
示例2:
CCMenuItemImage* Objects2dFactory::textButton(CCNode* scene, CCMenu* menu, string value, string normalImagePath, string selectedImagePath, string disabledImagePath,
float positionX, float positionY, float width, float height, SEL_MenuHandler selector, void* selectorArg, AlignX alignX, AlignY alignY, ccColor3B textColor, int zOrder)
{
// Check arguments validity
if(scene == NULL ||menu == NULL || !selector)
return NULL;
// Create a button menu item
CCMenuItemImage *button = CCMenuItemImage::create(
normalImagePath.c_str(),
selectedImagePath.c_str(),
disabledImagePath.c_str(),
scene,
selector);
if(!button)
return NULL;
if (selectorArg != NULL)
{
button->setUserData(selectorArg);
}
// Place the menu item in the given position
button->setPosition(ccp(positionX, positionY));
// Set menu item anchor
button->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
// Set menu item height
float buttonHeight = button->boundingBox().size.height;
float buttonPosScaleHeight = buttonHeight;
if (height > 0) // if height is defined, it is setted
{
button->setScaleY(height / buttonHeight);
buttonPosScaleHeight = height;
}
// Create a label and initialize with the given string
CCLabelTTF* pLabel = CCLabelTTF::create(value.c_str(), "Arial"/*string(Constants::getResourcesPath() + "SOResources/Fonts/AlphaFridgeMagnetsAllCap.ttf").c_str()*/,
buttonPosScaleHeight * 0.6f);
if(!pLabel)
return NULL;
// Set color
pLabel->setColor(textColor);
// Set menu item width
float buttonWidth = button->boundingBox().size.width;
float buttonPosScaleWidth = buttonWidth;
if (width > 0) // if width is defined, it is setted
{
button->setScaleX(width / buttonWidth);
buttonPosScaleWidth = width;
}
else // otherwise, we will compare the text width with the button width
{
float textWidth = pLabel->boundingBox().size.width;
if (textWidth * 1.25 > buttonWidth) // if the width adapted to the text is bigger than the button width, adapted width must be setted, otherwise, button width must stay as it was
{
button->setScaleX(textWidth * 1.25f / buttonWidth);
buttonPosScaleWidth = textWidth * 1.25f;
}
}
// Place the label; must be in the center of the button
pLabel->setPosition(ccp(buttonPosScaleWidth * 0.5f * 1/button->getScaleX(), buttonPosScaleHeight * 0.5f * 1/button->getScaleY()));
// Set label centered anchor
pLabel->setAnchorPoint(ccp(Constants::getAnchorValue(Centered), Constants::getAnchorValue(Middle)));
// Add label to button
button->addChild(pLabel);
// Set label scale; the inverse of button scale, so label can be as it would be if it was a child of scene
pLabel->setScaleY(1/button->getScaleY());
pLabel->setScaleX(1/button->getScaleX());
// If label is larger than button
if (pLabel->boundingBox().size.width * button->getScaleX() > button->boundingBox().size.width)
{
// Label must be rescaled
float newScale = button->boundingBox().size.width / (pLabel->boundingBox().size.width * button->getScaleX());
pLabel->setScaleX(pLabel->getScaleX() * newScale);
}
// Add button to the menu
menu->addChild(button, zOrder);
return button;
}
示例3: toServerList
void ThirdServerScene::toServerList() {
if (this->getChildByTag(loginLayerTag) != NULL) {
this->removeChildByTag(loginLayerTag,true);
}
CCLayer* loginLayer = CCLayer::create();
loginLayer->setTag(loginLayerTag);
loginLayer->setPosition(ccp(0,0));
CCLayer* displayLayer = CCLayer::create();
CCSprite* loginBack = CCSprite::createWithSpriteFrameName("serverShadow.png");
loginBack->setPosition(ccp(0,0));
loginBack->setAnchorPoint(ccp(1,0));
loginBack->setScale(2);
displayLayer->addChild(loginBack);
displayLayer->setTag(loginDisplayLayerTag);
loginLayer->addChild(displayLayer);
displayLayer->setPosition(ccp(winSize.width-645,960));
CCSprite* serverListLabel = CCSprite::createWithSpriteFrameName("serverlistTipLabel.png");
serverListLabel->setPosition(ccp(-285,325));
displayLayer->addChild(serverListLabel);
// CCSprite* upTip = CCSprite::createWithSpriteFrameName("serverlistTipCornor.png");
// upTip->setPosition(ccp(-300,65));
// upTip->setRotation(180);
// upTip->setScale(0.66);
// upTip->setColor(ccc3(200,200,200));
// upTip->setTag(upTipTag);
//
// displayLayer->addChild(upTip);
CCSprite* downTip = CCSprite::createWithSpriteFrameName("serverlistTipCornor.png");
downTip->setPosition(ccp(-300,50));
downTip->setScale(0.66);
downTip->setColor(ccc3(200,200,200));
downTip->setTag(downTipTag);
downTip->runAction(CCRepeatForever::create(static_cast<CCSequence*>(CCSequence::create( CCEaseIn::create(CCMoveBy::create(0.25,ccp(0,-10)),1.5),CCEaseOut::create(CCMoveBy::create(0.25,ccp(0,10)),1.5),NULL))));
displayLayer->addChild(downTip);
displayLayer->runAction(CCEaseElasticOut::create(CCMoveTo::create(0.35, ccp(winSize.width-394,280)), 1));
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_popCreator.mp3");
CCObject* obj;
int i = 0;
ServerSelectScroll2* scroll = ServerSelectScroll2::create(-507);
scroll->setOriPosition(ccp(winSize.width-890,370));
scroll->setContentSize(CCSizeMake(450, 200));
scroll->setMapSize(CCSizeMake(450, 50*(beans->count()+3)));
scroll->setPosition(ccp(winSize.width-765+0.33*50*(beans->count()-1)-224,-scroll->getMapSize().height+scroll->getViewSize().height+scroll->getOriPosition().y+680));
scroll->runAction(CCEaseElasticOut::create(CCMoveBy::create(0.35, ccp(224,-680)), 1));
CCARRAY_FOREACH(beans,obj) {
SeverInfoBean* bean = (SeverInfoBean*)obj;
CCSprite* layer = CCSprite::create("transparent.png");
// CCSprite* transParent = CCSprite::create("transparent.png");
layer->setScaleX(270/layer->getContentSize().width);
layer->setScaleY(33/layer->getContentSize().height);
layer->setContentSize(CCSizeMake(225,33));
layer->setOpacity(100);
CCLabelTTF* label = CCLabelTTF::create(bean->getServerName()->getCString(),"Arial",33);
label->setPosition(ccp(90/layer->getScaleX(),16/layer->getScaleY()));
layer->addChild(label,2);
label->setTag(serverNameLabelTag);
label->setScaleX(1/layer->getScaleX());
label->setScaleY(1/layer->getScaleY());
if (bean->serverId == cacheServerId) {
label->setColor(ccc3(155,155,155));
}
CCLabelTTF* stateLabel =CCLabelTTF::create(bean->getServerStatus()->getCString(),"Arial",30);
stateLabel->setPosition(ccp(236/layer->getScaleX(),16/layer->getScaleY()));
if (bean->getServerStatus()->compare("正常") == 0 || bean->getServerStatus()->compare("推荐") == 0) {
stateLabel->setColor(ccc3(0,255,0));
} else if (bean->getServerStatus()->compare("繁忙") == 0) {
stateLabel->setColor(ccc3(255,255,0));
} else if (bean->getServerStatus()->compare("火爆") == 0) {
stateLabel->setColor(ccc3(167,87,168));
} else {
stateLabel->setColor(ccc3(166,166,166));
}
stateLabel->setScaleX(1/layer->getScaleX());
stateLabel->setScaleY(1/layer->getScaleY());
layer->addChild(stateLabel,2);
MyMenuItem* serverItem = MyMenuItem::create(layer,this,menu_selector(ThirdServerScene::toChangeServer));
serverItem->setPosition(ccp(-(i+3)*17+135,26+50*(i+3)));
// serverItem->setAnchorPoint(ccp(0,0));
serverItem->setUserObject(bean);
scroll->addChild(serverItem);
// dividingLength*i+33
i++;
}