本文整理汇总了C++中CCNode::setAnchorPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ CCNode::setAnchorPoint方法的具体用法?C++ CCNode::setAnchorPoint怎么用?C++ CCNode::setAnchorPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCNode
的用法示例。
在下文中一共展示了CCNode::setAnchorPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ccp
GUISpinView::GUISpinView(CCRect viewFrame, float itemHeight, GUISpinViewDelegate * delegate):
m_delegate(NULL),
m_mainNode(NULL),
m_itemHeight(0),
m_itemCount(0),
m_targetRow(0),
m_currentRow(0)
{
m_delegate = delegate;
m_viewFrame = viewFrame;
m_itemHeight = itemHeight;
m_mainNode = CCNode::create();
m_mainNode->setAnchorPoint(ccp(0.5f, 0.5f));
m_mainNode->setPosition(ccpAdd(viewFrame.origin, ccp(viewFrame.size.width/2, viewFrame.size.height/2)));
addChild(m_mainNode);
m_itemCount = m_delegate->itemsCountForSpinView(this);
for (int i = 0; i < m_itemCount; i++) {
CCNode * node = m_delegate->createItemForSpinView(this, i);
m_mainNode->addChild(node, 0, i);
node->setAnchorPoint(ccp(0, 0.5f));
CCPoint p = ccp(0, - m_itemHeight * i);
if (p.y + m_itemHeight * 0.5f < - m_viewFrame.size.height * 0.5f) {
p.y = m_itemHeight * (m_itemCount - i);
}
node->setPosition(p);
}
}
示例2: setup
void NestedTest::setup()
{
static int depth = 9;
CCNode *parent = this;
for (int i = 0; i < depth; i++) {
int size = 225 - i * (225 / (depth * 2));
CCClippingNode *clipper = CCClippingNode::create();
clipper->setContentSize(CCSizeMake(size, size));
clipper->setAnchorPoint(ccp(0.5, 0.5));
clipper->setPosition( ccp(parent->getContentSize().width / 2, parent->getContentSize().height / 2) );
clipper->setAlphaThreshold(0.05f);
clipper->runAction(CCRepeatForever::create(CCRotateBy::create(i % 3 ? 1.33 : 1.66, i % 2 ? 90 : -90)));
parent->addChild(clipper);
CCNode *stencil = CCSprite::create(s_pPathGrossini);
stencil->setScale( 2.5 - (i * (2.5 / depth)) );
stencil->setAnchorPoint( ccp(0.5, 0.5) );
stencil->setPosition( ccp(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
stencil->setVisible(false);
stencil->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(i), CCShow::create()));
clipper->setStencil(stencil);
clipper->addChild(stencil);
parent = clipper;
}
}
示例3: init
bool MainLayer::init()
{
/*-- 设置整体层属性 --*/
this->setTouchMode(kCCTouchesOneByOne);
this->setTouchEnabled(true);
this->scheduleUpdate();
CCSize s = CCDirector::sharedDirector()->getWinSize();
this->ignoreAnchorPointForPosition(true);
setAnchorPoint(ccp(0.5f, 0.5f));
this->setContentSize(s);
setPosition(ccp(s.width / 2, s.height / 2));
CCSize vsize = CCDirector::sharedDirector()->getVisibleSize();
float width = vsize.width / 2;
float height = vsize.height / 2;
Counter *counter = Counter::sharedCounter();
counter->clearScore();
if (counter->isSound()
&& !SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
{
SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm.mp3", true);
}
/*-- door --*/
CCAnimation *doorAnimation =
CCAnimationCache::sharedAnimationCache()->animationByName("door");
//左侧
CCSprite *leftDoor = CCSprite::createWithSpriteFrameName("door_1.png");
leftDoor->setPosition(ccp(-200, -50));
leftDoor->setAnchorPoint(ccp(0.5, 0.5));
this->addChild(leftDoor);
leftDoor->runAction(
CCRepeatForever::create(CCAnimate::create(doorAnimation)));
//右侧
CCSprite *rightDoor = CCSprite::createWithSpriteFrameName("door_1.png");
rightDoor->setPosition(ccp(200, -50));
rightDoor->setAnchorPoint(ccp(0.5, 0.5));
this->addChild(rightDoor);
rightDoor->runAction(
CCRepeatForever::create(CCAnimate::create(doorAnimation)));
/*-- 分数 --*/
CCLabelTTF *titletxt = CCLabelTTF::create(counter->getStringByKey("score"),
counter->getStringByKey("font"), 46);
titletxt->setColor(ccc3(98, 104, 191));
titletxt->setAnchorPoint(ccp(0.5, 0.5));
titletxt->setPosition(ccp(0, height - 130));
this->addChild(titletxt);
CCNode *scoreLabel = counter->create_label();
scoreLabel->setPosition(ccp(0, height - 200));
scoreLabel->setAnchorPoint(ccp(0.5, 1));
this->addChild(scoreLabel, 3, TAG_SCORE);
/*-- role --*/
return true;
}
示例4: reArrange
void VEScrollView::reArrange()
{
CCArray *children = m_pContainer->getChildren();
float posX = -m_viewSize.width/2.f;
float posY = m_viewSize.height/2.f;
for(int i = 0; i < m_pContainer->getChildrenCount(); i++)
{
CCNode *node = (CCNode*)children->objectAtIndex(i);
CCSize nodeSize = node->getContentSize();
node->setAnchorPoint(ccp(0.5, 0.5));
switch (m_eType) {
case SCROLLVIEW_HORIZONTAL:
node->setPositionX(posX+nodeSize.width/2.f);
posX += nodeSize.width;
break;
case SCROLLVIEW_VERTICAL:
node->setPositionY(posY-nodeSize.height/2.f);
posY -= nodeSize.height;
break;
default:
CCLOG("wrong scroll type");
break;
}
//float nodeY = m_pContainer->getPositionY()+h;
//node->setVisible(nodeY<nodeSize.height && nodeY>-m_viewSize.height);
//if(dynamic_cast<CCLayer*>(node))
// dynamic_cast<CCLayer*>(node)->setTouchEnabled(nodeY<nodeSize.height && nodeY>-m_viewSize.height);
}
switch (m_eType) {
case SCROLLVIEW_HORIZONTAL:
posX += m_viewSize.width/2.f;
m_contentSize.width = abs(posX);
m_contentSize.height = m_viewSize.height;
break;
case SCROLLVIEW_VERTICAL:
posY -= m_viewSize.height/2.f;
m_contentSize.width = m_viewSize.width;
m_contentSize.height = abs(posY);
break;
default:
CCLOG("wrong scroll type");
break;
}
}
示例5: refresh
void GUISpinView::refresh()
{
m_mainNode->removeAllChildren();
m_itemCount = m_delegate->itemsCountForSpinView(this);
for (int i = 0; i < m_itemCount; i++) {
CCNode * node = m_delegate->createItemForSpinView(this, i);
m_mainNode->addChild(node, 0, i);
node->setAnchorPoint(ccp(0, 0.5f));
CCPoint p = ccp(0, - m_itemHeight * i);
if (p.y + m_itemHeight * 0.5f < - m_viewFrame.size.height * 0.5f) {
p.y = m_itemHeight * (m_itemCount - i);
}
node->setPosition(p);
}
}
示例6: runMovePreAction
void CMainCityUI::runMovePreAction(int tag)
{
CCNode *sBtn = dynamic_cast<CCNode*>( m_ui->getChildByTag(tag));
sBtn->setVisible(true);
CCArray *children = sBtn->getChildren();
for (int i = 0; i < sBtn->getChildrenCount(); i++)
{
CCNode *child = (CCNode*)children->objectAtIndex(i);
CCMoveBy *move = CCMoveBy::create(0.3f,ccp(-m_moveX[tag-1],0));
child->runAction(move);
child->setAnchorPoint(CCPointCenter);
child->setVisible(true);
}
}
示例7: init
bool CCControlPotentiometerTest::init()
{
if (CCControlScene::init())
{
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
CCNode *layer = CCNode::create();
layer->setPosition(ccp (screenSize.width / 2, screenSize.height / 2));
this->addChild(layer, 1);
double layer_width = 0;
// Add the black background for the text
CCScale9Sprite *background = CCScale9Sprite::create("extensions/buttonBackground.png");
background->setContentSize(CCSizeMake(80, 50));
background->setPosition(ccp(layer_width + background->getContentSize().width / 2.0f, 0));
layer->addChild(background);
layer_width += background->getContentSize().width;
this->setDisplayValueLabel(CCLabelTTF::create("", "HelveticaNeue-Bold", 30));
m_pDisplayValueLabel->setPosition(background->getPosition());
layer->addChild(m_pDisplayValueLabel);
// Add the slider
CCControlPotentiometer *potentiometer = CCControlPotentiometer::create("extensions/potentiometerTrack.png"
,"extensions/potentiometerProgress.png"
,"extensions/potentiometerButton.png");
potentiometer->setPosition(ccp (layer_width + 10 + potentiometer->getContentSize().width / 2, 0));
// When the value of the slider will change, the given selector will be call
potentiometer->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlPotentiometerTest::valueChanged), CCControlEventValueChanged);
layer->addChild(potentiometer);
layer_width += potentiometer->getContentSize().width;
// Set the layer size
layer->setContentSize(CCSizeMake(layer_width, 0));
layer->setAnchorPoint(ccp (0.5f, 0.5f));
// Update the value label
this->valueChanged(potentiometer, CCControlEventValueChanged);
return true;
}
return false;
}
示例8: CCListView_cellForRow
void MessageView::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)
{
// 背景
CCSprite* cellBg = CCSprite::create("bg_listview_item.png") ;
const float cell_width = cellBg->getContentSize().width+15 ;
const float cell_height = cellBg->getContentSize().height+10 ;
CCListViewCell* cell = CCListViewCell::node() ;
cell->setContentSize(CCSizeMake(cell_width, cell_height)) ;
cell->setOpacity(0) ;
// cell->setSelectionColor(ccc4(255, 0, 0, 255)) ;
cell->setSelectionColor(ccc4(103, 102, 204, 255)) ;
data->cell = cell ;
CCNode* cellNode = CCNode::create() ;
cellNode->setContentSize(CCSizeMake(cell_width, cell_height)) ;
cellNode->setAnchorPoint(ccp(0, 0)) ;
cellNode->setPosition(ccp(0, 0)) ;
cell->addChild(cellNode) ;
// 背景
cellBg->setAnchorPoint(ccp(0.5, 0.5)) ;
cellBg->setPosition(ccp(cell_width*0.5, cell_height*0.5)) ;
cellNode->addChild(cellBg) ;
// icon
CCSprite* iconMsg = CCSprite::create("icon_msg.png") ;
iconMsg->setAnchorPoint(ccp(0, 0.5)) ;
iconMsg->setPosition(ccp(20, cell_height*0.5)) ;
cellNode->addChild(iconMsg, 1) ;
// 主题
CCLabelTTF* themeLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币","font01.ttf", 24.0f,CCSizeMake(cell_width, 50),
kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ;
themeLabel->setColor(ccc3(255, 215, 0)) ;
themeLabel->setAnchorPoint(ccp(0, 1)) ;
themeLabel->setPosition(ccp(120, cell_height-8)) ;
cellNode->addChild(themeLabel, 1) ;
// 内容
CCLabelTTF* contentLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币,蛇年贺新春,免费拿九玩币","font01.ttf", 20.0f,CCSizeMake(cell_width, 50),
kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ;
contentLabel->setAnchorPoint(ccp(0, 0)) ;
contentLabel->setPosition(ccp(120, 8)) ;
cellNode->addChild(contentLabel, 1) ;
}
示例9: initGround
//地面生成
CCNode* ObjectManager::initGround(){
//物理ボディ生成
b2Body* body = _gameL->getWorld()->CreateBody(&groundBodyDef());
// 地面の形と大きさの定義
b2EdgeShape groundBox = groundShape();
//物理性質
b2FixtureDef fixtureDef;
fixtureDef.shape = &groundBox;
fixtureDef.density = 0.5;
fixtureDef.restitution = 0.5;
fixtureDef.friction = 0.8;
body->CreateFixture(&fixtureDef);
//地面ノード作成
CCNode* node = CCNode::create();
node->setAnchorPoint(ccp(0.5, 0.5));
node->setPosition(ccp(_gameL->getBgTag()->getContentSize().width / 2, 25));
_gameL->setNode(node);
return node;
}
示例10: createContainer
bool CCCGameScrollView::createContainer(CCCGameScrollViewDelegate *pDele, int nCount, const cocos2d::CCSize &oSize )
{
CCAssert(m_bSetDirection, "must call setDirection first!!!");
m_nPageCount = nCount;
m_CellSize = oSize;
setDelegate(pDele);
if (nCount==1) {
}
CCLayer *pContainer = CCLayer::create();
CCSize winSize =CCSizeZero ; //CCDirector::sharedDirector()->getVisibleSize();
for (int i = 0; i < nCount; ++i)
{
CCNode *pNode = CCNode::create();
pNode->setAnchorPoint(ccp(0, 0));
pDele->scrollViewInitPage(this, pNode, i);
if (m_eDirection == kCCScrollViewDirectionHorizontal)
{
pNode->setPosition(ccp( i * oSize.width, 0));
}
else
{
pNode->setPosition(ccp(0,i * oSize.height));
}
pNode->setContentSize(m_CellSize);
pNode->setTag(i);
pContainer->addChild(pNode);
}
setViewSize(m_CellSize);
setContainer(pContainer);
return true;
}
示例11: init
/**
* 初始化方法,继承CCLayer的方法
*/
bool LoginView::init()
{
if(!CCLayer::init())
{
return false ;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize() ;
// 背景
CCSprite* downBg = CCSprite::create("bg_welcome.png") ;
downBg->setAnchorPoint(ccp(0.5, 0)) ;
downBg->setPosition(ccp(winSize.width/2, 0)) ;
this->addChild(downBg, 0) ;
// 加载logo
CCSprite* logo = CCSprite::create("logo_01.png") ;
logo->setAnchorPoint(ccp(0.5, 0.5)) ;
logo->setPosition(ccp(winSize.width/2, winSize.height/2+35)) ;
this->addChild(logo, 1) ;
///////////////////////////////// 输入框 ////////////////////////////////////////
const float input_width = 213.0f ;
const float input_height = 39.0f ;
const float labelNode_padding = 8.0f ;
const float labelNode_width = winSize.width/3 ;
const float labelNode_height = 2*input_height+labelNode_padding ;
CCNode* labelNode = CCNode::create() ;
labelNode->setContentSize(CCSizeMake(labelNode_width, labelNode_height)) ;
labelNode->setAnchorPoint(ccp(0.5, 0)) ;
labelNode->setPosition(ccp(winSize.width/2-5, 85)) ;
this->addChild(labelNode, 2) ;
CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create("bg_textfield.png") ;
// 用户名
CCSprite* txtUsernameBg = CCSprite::createWithTexture(batchNode->getTexture()) ;
txtUsernameBg->setAnchorPoint(ccp(0, 0)) ;
txtUsernameBg->setPosition(ccp(0, input_height+labelNode_padding)) ;
labelNode->addChild(txtUsernameBg, 0) ;
this->txtUsername = CCTextFieldTTF::textFieldWithPlaceHolder("Username", CCSizeMake(input_width, input_height),
kCCTextAlignmentLeft, "font01.ttf", 26.0f) ;
this->txtUsername->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ;
this->txtUsername->setAnchorPoint(ccp(0, 0.5)) ;
this->txtUsername->setPosition(ccp((winSize.width-labelNode_width)/2+5, 85+labelNode_height*3/4)) ;
this->addChild(this->txtUsername, 3) ;
// 密码
CCSprite* txtPasswordBg = CCSprite::createWithTexture(batchNode->getTexture()) ;
txtPasswordBg->setAnchorPoint(ccp(0, 0)) ;
txtPasswordBg->setPosition(ccp(0, 0)) ;
labelNode->addChild(txtPasswordBg, 0) ;
this->txtPassword = CCTextFieldTTF::textFieldWithPlaceHolder("Password", CCSizeMake(input_width, input_height),
kCCTextAlignmentLeft, "font01.ttf", 26.0f) ;
this->txtPassword->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ;
this->txtPassword->setAnchorPoint(ccp(0, 0.5)) ;
this->txtPassword->setPosition(ccp((winSize.width-labelNode_width)/2+5, 85+labelNode_height/4-2)) ;
this->addChild(this->txtPassword,3) ;
// 登录按钮
CCMenuItemImage* loginMenuItem = CCMenuItemImage::create("menu_login_n.png", "menu_login_s.png", this, menu_selector(LoginView::menuLoginCallback)) ;
loginMenuItem->setAnchorPoint(ccp(0, 0)) ;
loginMenuItem->setPosition(ccp(0, input_height+labelNode_padding)) ;
// 注册按钮
CCMenuItemImage* registeMenuItem = CCMenuItemImage::create("menu_registe_n.png", "menu_registe_s.png", this, menu_selector(LoginView::menuRegisteCallback)) ;
registeMenuItem->setAnchorPoint(ccp(0, 0)) ;
registeMenuItem->setPosition(ccp(0, 0)) ;
CCMenu* loginMenu = CCMenu::create(loginMenuItem, registeMenuItem, NULL) ;
loginMenu->setAnchorPoint(ccp(0, 0)) ;
loginMenu->setPosition(ccp(input_width+10, -5)) ;
labelNode->addChild(loginMenu) ;
// //////////////////////////////////////////////////////////////////////////////////////////////
const float loginNode_padding = 11.0f ;
const float loginNode_margin_bottom = 32.0f ;
const float menu_item_width = 101.0f ;
CCNode* optionNode = CCNode::create() ;
optionNode->setContentSize(CCSizeMake(winSize.width/3, 50)) ;
optionNode->setAnchorPoint(ccp(0.5, 0)) ;
optionNode->setPosition(ccp(winSize.width/2-5, loginNode_margin_bottom)) ;
this->addChild(optionNode, 1) ;
// 游客登录
CCMenuItemImage* guestLoginItem = CCMenuItemImage::create("menu_guest_login_n.png", "menu_guest_login_s.png", this, menu_selector(LoginView::menuGuestLoginCallback)) ;
guestLoginItem->setAnchorPoint(ccp(0, 0)) ;
guestLoginItem->setPosition(ccp(0, 0)) ;
// 忘记密码
CCMenuItemImage* forgetPwdItem = CCMenuItemImage::create("menu_forget_pwd_n.png", "menu_forget_pwd_s.png", this, menu_selector(LoginView::menuForgetPwdCallback)) ;
//.........这里部分代码省略.........
示例12: initTopBar
// 初始化顶部bar
void ActivityView::initTopBar(CCSize winSize)
{
////////////////////////////////////////////////////////////////////////////////////////////////////
// topBarNode 背景
CCSprite* topBarBg = CCSprite::create("bg_nav_top.png") ;
topBarBg->setAnchorPoint(ccp(0.5, 0)) ;
topBarBg->setPosition(ccp(winSize.width/2, 0)) ;
const float topBar_height = topBarBg->getContentSize().height ;
// 顶部条信息 //////////////////////////////////////////////////////////////////////////////////////
this->topBarNode = CCNode::create() ;
this->topBarNode->setContentSize(CCSizeMake(winSize.width, topBar_height)) ;
this->topBarNode->setAnchorPoint(ccp(0, 0)) ;
this->topBarNode->setPosition(ccp(0, winSize.height - topBar_height)) ;
this->addChild(this->topBarNode, 0, 1) ;
// 将topBarNode背景加入到topBarNode
this->topBarNode->addChild(topBarBg, 0 ) ;
///////////////////////////// 左侧布局 //////////////////////////
CCNode* leftNode = CCNode::create() ;
leftNode->setContentSize(CCSizeMake(300, topBar_height)) ;
leftNode->setAnchorPoint(ccp(0, 0.5)) ;
leftNode->setPosition(ccp(30, topBar_height/2)) ;
this->topBarNode->addChild(leftNode, 1) ;
// 头像
CCSprite* headPortraitSprite = CCSprite::create("user/head_default_f2.png") ;
headPortraitSprite->setAnchorPoint(ccp(0, 0)) ;
headPortraitSprite->setPosition(ccp(0, 10)) ;
headPortraitSprite->setScale(0.8) ;
leftNode->addChild(headPortraitSprite) ;
// 昵称
CCLabelTTF* nikeNameLabel = CCLabelTTF::create("昵称:我是主角", "font01.ttf", 22.0f) ;
// nikeNameLabel->setColor(ccc3(191, 173, 111)) ;
nikeNameLabel->setAnchorPoint(ccp(0, 0)) ;
nikeNameLabel->setPosition(ccp(70, topBar_height/2+2)) ;
nikeNameLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式
nikeNameLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式
leftNode->addChild(nikeNameLabel) ;
// 金币
CCLabelTTF* goldCoinLabel = CCLabelTTF::create("金币:10000", "font01.ttf", 22.0f) ;
goldCoinLabel->setAnchorPoint(ccp(0, 1)) ;
goldCoinLabel->setPosition(ccp(70, topBar_height/2)) ;
goldCoinLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式
goldCoinLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式
leftNode->addChild(goldCoinLabel) ;
// 信息
CCSprite* titleMsg = CCSprite::create("icon_title_activity.png") ;
titleMsg->setAnchorPoint(ccp(0.5, 0.5)) ;
titleMsg->setPosition(ccp(winSize.width/2, topBar_height/2)) ;
this->topBarNode->addChild(titleMsg, 1) ;
// 分割线
CCSprite* spliteLineLeft = CCSprite::create("icon_top_nav_splite.png") ;
spliteLineLeft->setAnchorPoint(ccp(0, 1)) ;
spliteLineLeft->setPosition(ccp(winSize.width/3+10, topBar_height)) ;
this->topBarNode->addChild(spliteLineLeft, 1) ;
// 分割线
CCSprite* spliteLineRight = CCSprite::create("icon_top_nav_splite.png") ;
spliteLineRight->setAnchorPoint(ccp(0, 1)) ;
spliteLineRight->setPosition(ccp(winSize.width*2/3-20, topBar_height)) ;
this->topBarNode->addChild(spliteLineRight, 1) ;
/////////////////////////////////////////////////////////////////////////////////////////////////
/****************************** 菜单选项 ********************************************************/
// 右侧menu
const float right_width = 200 ;
const float item_width = 55 ;
// 礼物
CCMenuItemImage* menuGifts = CCMenuItemImage::create("menu_gifts_n.png", "menu_gifts_s.png", this,
menu_selector(ActivityView::menuGiftsClickCallback)) ;
// menuBack->setContentSize(CCSizeMake(67, 68)) ;
menuGifts->setAnchorPoint(ccp(0, 0.5)) ;
menuGifts->setPosition(ccp(0, topBar_height/2)) ;
//menuGifts->setPosition(ccp(right_width-2*item_width, topBar_height/2)) ;
//rightMenu->addChild(menuGifts) ;
// 返回大厅
CCMenuItemImage* menuBack = CCMenuItemImage::create("menu_back_n.png", "menu_back_s.png", this,
menu_selector(MessageView::menuBackClickCallback)) ;
menuBack->setAnchorPoint(ccp(0, 0.5)) ;
menuBack->setPosition(ccp(2*(item_width+10), topBar_height/2)) ;
//menuBack->setPosition(ccp(right_width, topBar_height/2)) ;
//rightMenu->addChild(menuBack) ;
//.........这里部分代码省略.........
示例13: initUI
//初始化UI
bool LayerGoods::initUI()
{
CCPoint vo = CCDirector::sharedDirector()->getVisibleOrigin();
CCSize vs = CCDirector::sharedDirector()->getVisibleSize();
UserInfo *user_info = Topwo::getInstance()->getTopwoData()->getUserInfo();
//背景
CCScale9Sprite* sp_bg = CCScale9Sprite::create(RES_white_dialog);
this->addChild(sp_bg);
sp_bg->setContentSize(CCSizeMake(780.0f, 340.0f));
CCSize size_sp_bg = sp_bg->getContentSize();
sp_bg->setPosition(ccp(vs.width * 0.5f, vs.height * 0.5f));
//标题
CCSprite *sp_title = CCSprite::create(RES_LayerGoods_title);
this->addChild(sp_title);
CCSize size_sp_title = sp_title->getContentSize();
sp_title->setPosition(ccp(vs.width * 0.5f, (vs.height + size_sp_bg.height) * 0.5f - size_sp_title.height * 0.8f));
//关闭项
CCMenuItemSprite *item_close = CCMenuItemSprite::create(
CCSprite::create(RES_btn_close_1_0),
CCSprite::create(RES_btn_close_1_0),
this,
menu_selector(LayerGoods::menuCallbackClose)
);
CCSize size_item_close = item_close->getContentSize();
CCNode *node = item_close->getNormalImage();
node->setAnchorPoint(ccp(0.5f, 0.5f));
node->setPosition(ccp(size_item_close.width * 0.5f, size_item_close.height * 0.5f));
node = item_close->getSelectedImage();
node->setAnchorPoint(ccp(0.5f, 0.5f));
node->setPosition(ccp(size_item_close.width * 0.5f, size_item_close.height * 0.5f));
node->setScale(1.2f);
item_close->setPosition(ccp((vs.width + size_sp_bg.width - size_item_close.width) * 0.5f, (vs.height + size_sp_bg.height - size_item_close.height) * 0.5f));
//购买物品1
CCSprite* sp_goods_1 = CCSprite::create(RES_LayerGoods_tipo);
this->addChild(sp_goods_1, 0 ,1);
CCSize size_sp_goods_1 = sp_goods_1->getContentSize();
sp_goods_1->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 2.04f, vs.height * 0.43f));
int goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelTiPo());
CCLabelAtlas* la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", goods_level)->getCString(), RES_number_style_5, 9, 12, '0');
sp_goods_1->addChild(la_value, 0, 0);
la_value->setAnchorPoint(ccp(0.5f, 0.5f));
la_value->setPosition(ccp(size_sp_goods_1.width * 0.45f, size_sp_goods_1.height * 0.56f));
la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString(), RES_number_style_2, 9, 15, '+');
sp_goods_1->addChild(la_value, 0, 1);
la_value->setAnchorPoint(ccp(0.5f, 0.5f));
la_value->setPosition(ccp(size_sp_goods_1.width * 0.68f, size_sp_goods_1.height * 0.48f));
la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString(), RES_number_style_2, 9, 15, '+');
sp_goods_1->addChild(la_value, 0, 2);
la_value->setAnchorPoint(ccp(0, 0.5f));
la_value->setPosition(ccp(size_sp_goods_1.width * 0.56f, size_sp_goods_1.height * 0.35f));
CCMenuItemSprite* item_buy_goods_1 = CCMenuItemSprite::create(
CCSprite::create(RES_btn_buy_0),
CCSprite::create(RES_btn_buy_1),
this,
menu_selector(LayerGoods::menuCallbackBuy)
);
item_buy_goods_1->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 2.04f, vs.height * 0.31f));
item_buy_goods_1->setTag(1);
//购买物品2
CCSprite* sp_goods_2 = CCSprite::create(RES_LayerGoods_meili);
this->addChild(sp_goods_2, 0, 2);
sp_goods_2->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 1.02f, vs.height * 0.43f));
goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelMeiLi());
la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", goods_level)->getCString(), RES_number_style_5, 9, 12, '0');
sp_goods_2->addChild(la_value, 0, 0);
la_value->setAnchorPoint(ccp(0.5f, 0.5f));
la_value->setPosition(ccp(size_sp_goods_1.width * 0.45f, size_sp_goods_1.height * 0.56f));
la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString(), RES_number_style_2, 9, 15, '+');
sp_goods_2->addChild(la_value, 0, 1);
la_value->setAnchorPoint(ccp(0.5f, 0.5f));
la_value->setPosition(ccp(size_sp_goods_1.width * 0.68f, size_sp_goods_1.height * 0.48f));
la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString(), RES_number_style_2, 9, 15, '+');
sp_goods_2->addChild(la_value, 0, 2);
la_value->setAnchorPoint(ccp(0, 0.5f));
la_value->setPosition(ccp(size_sp_goods_1.width * 0.56f, size_sp_goods_1.height * 0.35f));
CCMenuItemSprite* item_buy_goods_2 = CCMenuItemSprite::create(
CCSprite::create(RES_btn_buy_0),
CCSprite::create(RES_btn_buy_1),
this,
menu_selector(LayerGoods::menuCallbackBuy)
);
item_buy_goods_2->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 1.02f, vs.height * 0.31f));
item_buy_goods_2->setTag(2);
//.........这里部分代码省略.........
示例14: loadImages
void CCINode::loadImages(){
int tagIndex = 0;
while (true) {
CCIMovieTag * tag = NULL;
if (tagIndex<tags.size()) {
tag = tags[tagIndex++];
}else{
tagIndex = 0;
break;
}
if (tag->getTagType()==TagTypeDefineBitsLossless2 || tag->getTagType()==TagTypeDefineBitsJPEG3||tag->getTagType()==TagTypeDefineBitsJPEG2||tag->getTagType()==TagTypeDefineBits) {
CCIImageTag* imageTag = (CCIImageTag*)tag;
CCTexture2D * text = imageTag->getTexture();
if (text) {
this->textures->setObject(text, imageTag->getCharacterID());
}
}else if(tag->getTagType()==TagTypeDefineShape||tag->getTagType()==TagTypeDefineShape2||tag->getTagType()==TagTypeDefineShape3){
//shape是可以放上去的精灵
CCIDefineShape * defineShapeTag = (CCIDefineShape *)tag;
CCIRect *bounds = defineShapeTag->getBounds();
CCNode * shape = CCNode::create();
//CCNode * shape = CCLayerColor::create(ccc4(200,0,0,100));
shape->ignoreAnchorPointForPosition(false);
shape->setContentSize(bounds->getSize());
shape->setAnchorPoint(bounds->getAnchorPoint());
//shape->ignoreAnchorPointForPosition(true);
shape->setUserObject(CCInteger::create(NodeTypeNode));
CCIShapeWithStyle * style = defineShapeTag->getShapes();
CCIFillStyleArray * fileStyles = style->FillStyles;
this->fillNodeWithStyle(fileStyles, shape,bounds);
for (int i=0; i<style->ShapeRecords.size(); i++) {
CCIShapeRecord * record = style->ShapeRecords[i];
if (record->ShapeType==ShapeTypeStyle){
CCIStyleChangeRecord * styleRecord = (CCIStyleChangeRecord *)record;
if (styleRecord->StateNewStyles) {
fileStyles = styleRecord->FillStyles;
this->fillNodeWithStyle(fileStyles, shape,bounds);
}
}
}
this->nodes->setObject(shape, defineShapeTag->getShapeId());
}else if(tag->getTagType()==TagTypeDefineSprite){
CCIDefineSprite * sprite = (CCIDefineSprite *)tag;
CCINode * node = CCINode::createWithTags(sprite->getControlTags(), this->swfMovie,this->nodes);
node->setUserObject(CCInteger::create(NodeTypeCCINode));
this->nodes->setObject(node, sprite->getSpriteId());
}
}
}
示例15: updateNodesPosition
void CListView::updateNodesPosition()
{
m_pContainer->removeAllChildrenWithCleanup(true);
if( m_vNodeList.size() == 0 )
return;
m_fLayoutIndexSize = 0.0f;
switch( m_eDirection )
{
case eScrollViewDirectionHorizontal:
{
unsigned int i = 0;
unsigned int end = m_vNodeList.size();
CCNode* pNode = NULL;
for(; i < end; ++i )
{
pNode = m_vNodeList[i];
pNode->setAnchorPoint(ListViewHorizontalNodeAnchorPoint);
pNode->setPosition(CCPoint(m_fLayoutIndexSize, 0));
m_fLayoutIndexSize += pNode->getContentSize().width;
}
setContainerSize(CCSize(m_fLayoutIndexSize, m_obContentSize.height));
}
break;
case eScrollViewDirectionVertical:
{
float fAllNodesSize = 0.0f;
unsigned int i = 0;
unsigned int end = m_vNodeList.size();
CCNode* pNode = NULL;
for(; i < end; ++i )
{
pNode = m_vNodeList[i];
fAllNodesSize += pNode->getContentSize().height;
}
m_fLayoutIndexSize = fAllNodesSize;
fAllNodesSize = MAX(m_obContentSize.height, fAllNodesSize);
setContainerSize(CCSize(m_obContentSize.width, fAllNodesSize));
i = 0;
end = m_vNodeList.size();
for(; i < end; ++i )
{
pNode = m_vNodeList[i];
fAllNodesSize = fAllNodesSize - pNode->getContentSize().height;
pNode->setAnchorPoint(ListViewVerticalNodeAnchorPoint);
pNode->setPosition(CCPoint(0, fAllNodesSize));
m_pContainer->addChild(pNode);
}
}
break;
default:
break;
}
}