本文整理汇总了C++中Scale9Sprite::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Scale9Sprite::setPosition方法的具体用法?C++ Scale9Sprite::setPosition怎么用?C++ Scale9Sprite::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scale9Sprite
的用法示例。
在下文中一共展示了Scale9Sprite::setPosition方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tableCellAtIndex
TableViewCell* SkillTableView::tableCellAtIndex(TableView *table, ssize_t idx)
{
CCString* str = CCString::createWithFormat("ui/skill/skill_%d.png",2001 + (int)idx);
TableViewCell* cell = table->dequeueCell();
if (!cell)
{
cell = new TableViewCell();
cell->autorelease();
Scale9Sprite* bg = Scale9Sprite::create("ui/cell.png");
bg->setAnchorPoint(Point::ZERO);
bg->setPosition(Point::ZERO);
bg->setPreferredSize(Size(420, 80));
cell->addChild(bg);
Sprite* skill = Sprite::create(str->getCString());
skill->setPosition(Point(50, 40));
cell->addChild(skill, 0, 123);
m_skillVec.push_back(skill);
}
else
{
Sprite* skill = (Sprite*)cell->getChildByTag(123);
Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(str->getCString());
skill->setTexture(texture);
}
cell->setTag(2001+(int)idx);
return cell;
}
示例2: semiselected
void PubSprite::semiselected()
{
if (pub_sprite_ == NULL)
return;
const float kDisplayWidth = 354.0 * gScale;
const float kDisplayHeight = 530.0 * gScale;
Rect inset_rect = CCRectMake(38, 29, 1, 1);
Rect full_rect = CCRectMake(0, 0, 74, 284);
pub_sprite_->removeAllChildren();
/* add the sun state */
Sprite *sun = Sprite::create("main_screen/sun_semi.png");
const float kSunOffsetY = 317;
if (gScale == 1.0)
sun->setPosition(ccp(kDisplayWidth*2/3, kDisplayHeight*2/3+kSunOffsetY));
else
sun->setPosition(ccp(kDisplayWidth, kDisplayHeight+kSunOffsetY));
sun->setTag(2);
pub_sprite_->addChild(sun, 1);
/* add the white border*/
const float kBorderWidth = 480;
const float kBorderHeight = 706;
const float kBorderX = 226;
const float kBorderY = 336;
Scale9Sprite *yborder = Scale9Sprite::create("main_screen/border_selected.png", full_rect, inset_rect);
yborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight));
yborder->setPosition(ccp(kBorderX, kBorderY));
yborder->setTag(2);
pub_sprite_->addChild(yborder);
}
示例3: unseleted
void PubSprite::unseleted()
{
if (pub_sprite_ == NULL)
return;
const float kDisplayWidth = 354.0 * gScale;
const float kDisplayHeight = 530.0 * gScale;
Rect inset_rect = CCRectMake(11, 13, 1, 1);
Rect full_rect = CCRectMake(0, 0, 22, 23);
pub_sprite_->removeAllChildren();
/* add the cloud state */
Sprite *cloud = Sprite::create("main_screen/cloud_unselected.png");
const float kCloudOffsetY = 317;
if (gScale == 1.0)
cloud->setPosition(ccp(kDisplayWidth*2/3, kDisplayHeight*2/3+kCloudOffsetY));
else
cloud->setPosition(ccp(kDisplayWidth, kDisplayHeight+kCloudOffsetY));
cloud->setTag(1);
pub_sprite_->addChild(cloud, 1);
/* add the white border*/
const float kBorderWidth = 460;
const float kBorderHeight = 685;
const float kBorderX = 226;
const float kBorderY = 336;
Scale9Sprite *wborder = Scale9Sprite::create("main_screen/border_unselected.png", full_rect, inset_rect);
wborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight));
wborder->setPosition(ccp(kBorderX, kBorderY));
wborder->setTag(1);
pub_sprite_->addChild(wborder);
}
示例4: onEnter
void DialogLayer::onEnter()
{
Layer::onEnter();
Size winSize = Director::getInstance()->getWinSize();
Point pCenter = Point(winSize.width / 2, winSize.height / 2);
Size contentSize;
// 设定好参数,在运行时加载
if (getContentSize().equals(Size::ZERO)) {
getSpriteBackGround()->setPosition(winSize.width / 2, winSize.height / 2);
this->addChild(getSpriteBackGround(), 0, 0);
contentSize = getSpriteBackGround()->getTexture()->getContentSize();
} else {
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(getContentSize());
background->setPosition(winSize.width / 2, winSize.height / 2);
this->addChild(background, 0, 0);
contentSize = getContentSize();
}
// 添加按钮,并设置其位置
this->addChild(getMenuButton());
float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
Vector<Node*> vecArray = getMenuButton()->getChildren();
Ref* pObj = NULL;
int i = 0;
for(auto& e : vecArray){
Node* node = dynamic_cast<Node*>(e);
node->setPosition(Point(winSize.width/2 - contentSize.width/2+btnWidth*(i+1),winSize.height/2-contentSize.height/3));
i++;
}
// 显示对话框标题
if (getLabelTitle()){
getLabelTitle()->setPosition(pCenter + Vec2(0, contentSize.height / 2 - 30.0f));
this->addChild(getLabelTitle());
}
// 显示文本内容
if (getLabelContentText()){
LabelTTF* ltf = getLabelContentText();
ltf->setPosition(winSize.width / 2, winSize.height / 2 + 20);
//ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
this->addChild(ltf);
}
// 弹出效果
Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
ScaleTo::create(0.06, 1.05),
ScaleTo::create(0.08, 0.95),
ScaleTo::create(0.08, 1.0), NULL);
this->runAction(popupLayer);
}
示例5: selected
void PubSprite::selected()
{
if (pub_sprite_ == NULL)
return;
const float kDisplayWidth = 354.0 * gScale;
const float kDisplayHeight = 530.0 * gScale;
Rect inset_rect = CCRectMake(38, 29, 1, 1);
Rect full_rect = CCRectMake(0, 0, 74, 284);
pub_sprite_->removeAllChildren();
/**
* add the sun state
*/
Sprite *sun = Sprite::create("main_screen/sun_selected.png");
/* gScale is 1 means 1080p, so 2/3 is a fixed number to get the right position */
const float kSunOffsetY = 317;
if (gScale == 1.0)
sun->setPosition(ccp(kDisplayWidth*2/3, kDisplayHeight*2/3+kSunOffsetY));
else
sun->setPosition(ccp(kDisplayWidth, kDisplayHeight+kSunOffsetY));
sun->setTag(2);
pub_sprite_->addChild(sun, 1);
/**
* add the white border
*/
const float kBorderWidth = 480;
const float kBorderHeight = 706;
const float kBorderX = 226;
const float kBorderY = 336;
Scale9Sprite *yborder = Scale9Sprite::create("main_screen/border_selected.png", full_rect, inset_rect);
yborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight));
yborder->setPosition(ccp(kBorderX, kBorderY));
yborder->setTag(2);
pub_sprite_->addChild(yborder);
if (pub_title_ != NULL){
int size = 36;
if (strlen(pub_title_) > 35){
size = 32;
}
LabelTTF *title= LabelTTF::create(pub_title_, "Arial", size);
CCLog("title %s, length %d", pub_title_, strlen(pub_title_));
title->setFontFillColor(ccc3(255, 255, 0));
pub_sprite_->addChild(title);
const float kTitleOffsetX = 10;
const float kTitleOffsetY = 60;
if (gScale == 1.0)
title->setPosition(kDisplayWidth*2/3-kTitleOffsetX, kTitleOffsetY);
else
title->setPosition(kDisplayWidth-kTitleOffsetX, kTitleOffsetY);
}
}
示例6: showpubUnselect
void PubSprite::showpubUnselect()
{
pub_sprite_->removeAllChildren();
const float kDisplayWidth = 290.0 * gScale;
const float kDisplayHeight = 544.0 * gScale;
Rect inset_rect = CCRectMake(12, 12, 1, 1);
Rect full_rect = CCRectMake(0, 0, 23, 73);
/* add the cloud state */
Sprite *cloud = Sprite::create("main_screen/cloud_unselected.png");
const float kCloudOffsetY = 295;
const float kCloudOffsetX = 55;
if (gScale == 1.0)
cloud->setPosition(ccp(kDisplayWidth*2/3+kCloudOffsetX, kDisplayHeight*2/3+kCloudOffsetY));
else
cloud->setPosition(ccp(kDisplayWidth+kCloudOffsetX, kDisplayHeight+kCloudOffsetY));
cloud->setTag(1);
pub_sprite_->addChild(cloud, 1);
/**
* add the white border
*/
const float kBorderWidth = 460;
const float kBorderHeight = 730;
const float kBorderX = 225;
const float kBorderY = 310;
Scale9Sprite *wborder = Scale9Sprite::create("showlist/border_unselected.png", full_rect, inset_rect);
wborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight));
wborder->setPosition(ccp(kBorderX, kBorderY));
wborder->setTag(2);
pub_sprite_->addChild(wborder);
if (pub_title_ != NULL){
int size = 36;
if (strlen(pub_title_) > 30){
size = 32;
}
LabelTTF *title= LabelTTF::create(pub_title_, "Arial", size);
/** the color is blue */
title->setFontFillColor(ccc3(67, 155, 203));
pub_sprite_->addChild(title);
const float kTitleOffsetX = 20;
const float kTitleOffsetY = 20;
if (gScale == 1.0)
title->setPosition(kDisplayWidth*2/3+kTitleOffsetX, -kTitleOffsetY);
else
title->setPosition(kDisplayWidth+kTitleOffsetX, -kTitleOffsetY);
}
}
示例7: showpubSelect
void PubSprite::showpubSelect()
{
pub_sprite_->removeAllChildren();
const float kDisplayWidth = 290.0 * gScale;
const float kDisplayHeight = 544.0 * gScale;
Sprite *sun = Sprite::create("main_screen/sun_semi.png");
const float kSunOffsetY = 315;
const float kSunOffsetX = 35;
if (gScale == 1.0)
sun->setPosition(ccp(kDisplayWidth*2/3+kSunOffsetX, kDisplayHeight*2/3+kSunOffsetY));
else
sun->setPosition(ccp(kDisplayWidth+kSunOffsetX, kDisplayHeight+kSunOffsetY));
sun->setTag(2);
pub_sprite_->addChild(sun, 1);
Rect inset_rect = CCRectMake(30, 27, 1, 1);
Rect full_rect = CCRectMake(0, 0, 60, 120);
const float kBorderWidth = 500;
const float kBorderHeight = 775;
const float kBorderX = 225;
const float kBorderY = 298;
Scale9Sprite *yborder = Scale9Sprite::create("showlist/border_selected.png", full_rect, inset_rect);
yborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight));
yborder->setPosition(ccp(kBorderX, kBorderY));
yborder->setTag(2);
pub_sprite_->addChild(yborder);
if (pub_title_ != NULL){
int size = 46;
if (strlen(pub_title_) > 38){
size = 32;
}
LabelTTF *title= LabelTTF::create(pub_title_, "Arial", size);
/** the color is blue */
title->setFontFillColor(ccc3(67, 155, 203));
pub_sprite_->addChild(title);
const float kTitleOffsetX = 20;
const float kTitleOffsetY = 30;
if (gScale == 1.0)
title->setPosition(kDisplayWidth*2/3+kTitleOffsetX, -kTitleOffsetY);
else
title->setPosition(kDisplayWidth+kTitleOffsetX, -kTitleOffsetY);
}
}
示例8: onEnter
void PopupLayer::onEnter(){
LayerColor::onEnter();
Size winSize = CCDirector::getInstance()->getWinSize();
Point pCenter = Point(winSize.width / 2, winSize.height / 2);
// Size contentSize ;
// 设定好参数,在运行时加载
//如果没有设置 ContentSize ,那么采取的方案是,窗口大小与传入图片一样大
// if (getContentSize().equals(this->getParent()->getContentSize())) {
// getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
// this->addChild(getSpriteBackGround(), 0, 0);
// contentSize = getSpriteBackGround()->getTexture()->getContentSize();
// } else {
// Scale9Sprite *background = getSprite9BackGround();
// background->setContentSize(getContentSize());
// background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
// this->addChild(background, 0, 0);
// contentSize = getContentSize();
// }
//添加背景图片
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(m_dialogContentSize);
background->setPosition(Point(winSize.width / 2, winSize.height / 2));
this->addChild(background,0,0);
// 弹出效果
Action* popupLayer = Sequence::create(
ScaleTo::create(0.0, 0.0),
ScaleTo::create(0.2, 1.05),
ScaleTo::create(0.2, 0.95),
ScaleTo::create(0.1, 1.0),
CallFunc::create(CC_CALLBACK_0(PopupLayer::backgroundFinish,this)),
NULL
);
background->runAction(popupLayer);
}
示例9: onEnter
void PopLayer::onEnter()
{
Layer::onEnter();
Size winSize = Director::getInstance()->getVisibleSize();
Vec2 pCenter(winSize.width / 2, winSize.height / 2);
Size contentSize;
// 设定好参数,在运行时加载
if (getContentSize().equals(Size::ZERO)) {
getSpriteBackGround()->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
this->addChild(getSpriteBackGround(), 0, 0);
contentSize = getSpriteBackGround()->getTexture()->getContentSize();
} else {
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(getContentSize());
background->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
this->addChild(background, 0, 0);
contentSize = getContentSize();
}
// 添加按钮,并设置其位置
this->addChild(getMenuButton());
float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
Vector<Node *> array = getMenuButton()->getChildren();
getMenuButton()->alignItemsHorizontallyWithPadding(50);
getMenuButton()->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - contentSize.height / 3));
// int i = 0;
// for(auto &bt: array)
// {
// Node* node = dynamic_cast<Node*>(bt);
// node->setPosition(Vec2( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
// i++;
// }
// 显示对话框标题
if (getLabelTitle()){
getLabelTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 35.0f)));
this->addChild(getLabelTitle());
}
if(getImgTitle())
{
getImgTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 40.0f)));
this->addChild(getImgTitle());
}
// 显示文本内容
if (getLabelContentText()){
LabelTTF* ltf = getLabelContentText();
//ltf->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
ltf->setPosition(pCenter);
ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
ltf->setHorizontalAlignment(TextHAlignment::LEFT);
this->addChild(ltf);
}
// 弹出效果
Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
ScaleTo::create(0.06, 1.05),
ScaleTo::create(0.08, 0.95),
ScaleTo::create(0.08, 1.0), NULL);
this->runAction(popupLayer);
}
示例10: onEnter
void PopupLayer::onEnter(){
CCLayer::onEnter();
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);
CCSize contentSize;
// 设定好参数,在运行时加载
if (getContentSize().equals(CCSizeZero)) {
getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(getSpriteBackGround(), 0, 0);
contentSize = getSpriteBackGround()->getTexture()->getContentSize();
} else {
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(getContentSize());
background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(background, 0, 0);
contentSize = getContentSize();
}
// 添加按钮,并设置其位置
this->addChild(getMenuButton());
float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
// Array* array = getMenuButton()->getChildren();
Vector<Node*>& array = getMenuButton()->getChildren();
Object* pObj = NULL;
int i = 0;
/*
vector<NODE>::iterator it;
for (it=v.begin(); it!=v.end(); it++)
{
v[*it]->id=2;
}
*/
Vector<Node*>::iterator it;
for (it=array.begin() ; it!=array.end(); it++) {
Node* node = dynamic_cast<Node*>(pObj);
node->setPosition(ccp( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
i++;
}
// 显示对话框标题
if (getLabelTitle()){
getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, contentSize.height / 2 - 35.0f)));
this->addChild(getLabelTitle());
}
// 显示文本内容
if (getLabelContentText()){
CCLabelTTF* ltf = getLabelContentText();
ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
this->addChild(ltf);
}
// 弹出效果
CCAction* popupLayer = CCSequence::create(CCScaleTo::create(0.0, 0.0),
CCScaleTo::create(0.06, 1.05),
CCScaleTo::create(0.08, 0.95),
CCScaleTo::create(0.08, 1.0), NULL);
this->runAction(popupLayer);
}
示例11: onEnter
void PopupLayer::onEnter()
{
Layer::onEnter();
//Size winSize = Director::getInstance()->getWinSize();
Point pCenter = ccp(winSize.width / 2, winSize.height / 2);
Size contentSize;
// 设定好参数,在运行时加载
if (getContentSize().equals(CCSizeZero))
{
getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(getSpriteBackGround(), 0, 0);
contentSize = getSpriteBackGround()->getTexture()->getContentSize();
} else {
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(getContentSize());
background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(background, 0, 0);
contentSize = getContentSize();
}
// 添加按钮,并设置其位置
this->addChild(getMenuButton());
float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
Vector<Node*> vecArray = getMenuButton()->getChildren();
int j=0;
for(auto it=vecArray.begin();it!=vecArray.end();it++)
{
Node* node = dynamic_cast<Node*>(*it);
node->setPosition(Point(winSize.width/2 - contentSize.width/2+btnWidth*(j+1),winSize.height/2-contentSize.height/3));
j++;
}
// 显示对话框标题
if (getLabelTitle())
{
getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, contentSize.height / 2 -20)));
getLabelTitle()->setColor(ccc3(0,0,0));
this->addChild(getLabelTitle());
}
switch(pop_type)
{
case LOTTERY:
{
setLotteryContext(contentSize);
break;
}
case LOTTERY_PUBLISH:
{
setPublishLotteryContext(contentSize);
break;
}
case LOADGAME:
{
setLoadGameContext(contentSize);
break;
}
default:
{
// 显示文本内容
if (getLabelContentText())
{
LabelTTF* ltf = getLabelContentText();
ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
ltf->setColor(ccc3(0,0,0));
this->addChild(ltf);
}
}
}
// 弹出效果
Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
ScaleTo::create(0.15, 1.05),
ScaleTo::create(0.08, 0.95),
ScaleTo::create(0.08, 1.0),
NULL);
this->runAction(popupLayer);
}