本文整理汇总了C++中CCLayer::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLayer::setPosition方法的具体用法?C++ CCLayer::setPosition怎么用?C++ CCLayer::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLayer
的用法示例。
在下文中一共展示了CCLayer::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: touchUpInside
void GeneralDialogTest::touchUpInside(CCObject* pSender, CCControlEvent event)
{
CCLOG("GeneralDialogTest::touchUpInside");
CCLayer* layer = new GeneralLayer((CCLayer*)DialogLayerLoader::createCell());
layer->setPosition(ccp(0, 0));
addChild(layer);
}
示例2: updateLayerMessageBox
void AssetsUpdateLayer::updateLayerMessageBox()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ccb/ccbResources/SystemLoading.plist");
CCLayer* layer = CCLayer::create();
layer->ignoreAnchorPointForPosition(false);
layer->setContentSize(Size(960, 640));
layer->setPosition(Point(Director::getInstance()->getWinSize().width * 0.5, Director::getInstance()->getWinSize().height * 0.5));
layer->setScale(Director::getInstance()->getWinSize().width / 960);
addChild(layer, 1);
Sprite* messageboxSprite = Sprite::createWithSpriteFrameName("set_floor_v1.png");
messageboxSprite->setPosition(Point(480, 320));
layer->addChild(messageboxSprite, 1);
LabelTTF* labelContent = LabelTTF::create(Localization::getInstance()->getValueByKey("Loading_warning_need_update"), "Helvetica",32);
labelContent->setPosition(Point(480, 420));
layer->addChild(labelContent, 1);
ControlButton* btn = ControlButton::create(LabelTTF::create(Localization::getInstance()->getValueByKey("BUTTON_DONE"), "Helvetica", 32), Scale9Sprite::createWithSpriteFrameName("set_button2.png"));
btn->setPreferredSize(CCSize(191,70));
btn->setPosition(Point(480, 220));
btn->addTargetWithActionForControlEvents(this, cccontrol_selector(AssetsUpdateLayer::GoToAppPage), Control::EventType::TOUCH_UP_INSIDE);
layer->addChild(btn, 1);
}
示例3: setTipLayer
void HelpScene::setTipLayer(CCLayer* tipLayer){
CCSprite* bottom = SPRITE(bottom.png);
bottom->setPosition(ccp(VisibleRect::bottom().x,VisibleRect::bottom().y+35));
tipLayer->addChild(bottom);
GiantPageScrollView* tipsScrollView = GiantPageScrollView::create();
tipsScrollView->setPosition(VisibleRect::center());
tipsScrollView->cellSize = CCDirector::sharedDirector()->getWinSize();
tipsScrollView->tableSize = CCDirector::sharedDirector()->getWinSize();
tipsScrollView->cellNum = 4;
tipsScrollView->cells = CCArray::createWithCapacity(4);
for(int i=0;i<4;i++){
CCLayer* tipItem = CCLayer::create();
CCString* sprName = CCString::createWithFormat("tips_%d.png",i+1);
CCString* tipName = CCString::createWithFormat("tips_text_%d_CN.png",i+1);
CCSprite* tipStr = CCSprite::createWithSpriteFrameName(tipName->getCString());
CCSprite* tip = CCSprite::createWithSpriteFrameName(sprName->getCString());
tip->setPosition(VisibleRect::center());
tipStr->setPosition(ccp(VisibleRect::center().x,VisibleRect::center().y-200));
tipItem->ignoreAnchorPointForPosition(false);
tipItem->setPosition(VisibleRect::center());
tipItem->addChild(tip);
tipItem->addChild(tipStr);
tipsScrollView->cells->addObject(tipItem);
}
tipsScrollView->cells->retain();
tipLayer->addChild(tipsScrollView);
}
示例4: compareCallback
void HelloWorld::compareCallback(CCObject* pSender)
{
CCScene* scene = CCScene::create();
CCLayer* layer = SingleTouch::create();
layer->setPosition(0,100);
layer->setScale(0.5);
scene->addChild(layer);
CCLayer* layer1 = SingleTouch1::create();
scene->addChild(layer1);
layer1->setPosition(200,100);
layer1->setScale(0.5);
CCDirector::sharedDirector()->replaceScene(scene);
}
示例5: updatePages
void CCScrollLayer::updatePages()
{
// Loop through the array and add the screens if needed.
int i = 0;
CCObject* object = NULL;
CCARRAY_FOREACH(m_pLayers, object)
{
CCLayer* layer = (CCLayer*)object;
layer->setAnchorPoint(ccp(0,0));
layer->setContentSize(CCDirector::sharedDirector()->getWinSize());
layer->setPosition(ccp((i * (m_tContentSize.width - m_fPagesWidthOffset)), 0));
if (!layer->getParent())
addChild(layer);
i++;
}
示例6: setPageIndicator
//Page Indicator
void GroupCustomization::setPageIndicator(int currentPage, int count)
{
//set parameters
int interval = 22;
int opacity = 70;
//draw indicator
this->removeChildByTag(PAGE_INDICATOR,1);
CCLayer* pi = CCLayer::node();
addChild(pi,2,PAGE_INDICATOR);
pi->setPosition(ccp(0,0));
CCSprite* dots[4];
for(int i=0;i<count;i++)
{
dots[i]=CCSprite::spriteWithFile("GroupCustomization/dot.png");
pi->addChild(dots[i],2);
dots[i]->setPosition(ccp(x-((dots[i]->getContentSize().width*count+interval*count)/count)+i*interval,25));
if(i!=currentPage-1) dots[i]->setOpacity(opacity);
}
}
示例7: initWithLayers
bool CCScrollLayer::initWithLayers(CCArray *layers, int widthOffset)
{
if (CCLayer::init())
{
// Make sure the layer accepts touches
(CCDirector::sharedDirector()->getTouchDispatcher())->addTargetedDelegate(this,0,false);
// Set up the starting variables
if(!widthOffset)
{
widthOffset = 0;
}
currentScreen = 1;
// offset added to show preview of next/previous screens
scrollWidth = (int)CCDirector::sharedDirector()->getWinSize().width - widthOffset;
scrollHeight = (int)CCDirector::sharedDirector()->getWinSize().height;
startWidth = scrollWidth;
startHeight = scrollHeight;
// Loop through the array and add the screens
unsigned int i;
for (i=0; i<layers->count(); i++)
{
CCLayer* l = (CCLayer*)layers->objectAtIndex(i);
l->setAnchorPoint(ccp(0,0));
l->setPosition(ccp((i*scrollWidth),0));
addChild(l,1,i+2000);
}
// Setup a count of the available screens
totalScreens = layers->count();
return true;
}
else
{
return false;
}
}
示例8: onLoadScene
void MenuScene::onLoadScene()
{
m_vMenuItems.push_back("Basic Test");
CCSize tContainerSize = CCSize(700, 100 * m_vMenuItems.size());
CCLayer* pScrollViewContainer = CCLayer::create();
pScrollViewContainer->setPosition(CCPointZero);
pScrollViewContainer->setContentSize(tContainerSize);
m_pScrollView = CCScrollView::create(CCSize(700, 640));
m_pScrollView->setDirection(kCCScrollViewDirectionVertical);
m_pScrollView->ignoreAnchorPointForPosition(false);
m_pScrollView->setPosition(CCPoint(480, 320));
m_pScrollView->setContainer(pScrollViewContainer);
addChild(m_pScrollView);
CCArray* pArray = CCArray::create();
float height = tContainerSize.height;
unsigned int i = 0;
unsigned int end = m_vMenuItems.size();
for(; i < end; ++i )
{
CCMenuItemFont* pFont = CCMenuItemFont::create(m_vMenuItems[i].c_str());
pFont->setTarget(this, menu_selector(MenuScene::onClick));
pFont->setFontSizeObj(45.0f);
pFont->setPosition(ccp(700 / 2, height - 100 / 2));
pFont->setTag(i + 1);
pArray->addObject(pFont);
height -= 100;
}
CCMenu* pMenu = CCMenu::createWithArray(pArray);
pMenu->setPosition(ccp(0,0));
pScrollViewContainer->addChild(pMenu);
m_pScrollView->setContentOffset(ccp(0, -(tContainerSize.height - 640)));
}
示例9: setViewPoint
void Player::setViewPoint() {
if (mSprite == NULL) {
return;
}
CCLayer * parent = (CCLayer*)getParent();
CCSize mapTildNum = mditu->getMapSize();
CCSize tiledSize = mditu->getTileSize();
CCSize mapSize = CCSize::CCSize(mapTildNum.width*tiledSize.width,mapTildNum.height*tiledSize.height);
CCSize visblesize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint posSp = getPosition();
float x =fmax(posSp.x,visblesize.width/2);
float y = fmax(posSp.y,visblesize.height/2);
x = fmin(x, mapSize.width-visblesize.width/2);
y = fmin(y, mapSize.height-visblesize.height/2);
CCPoint TagPos = CCPoint::CCPoint(x,y);
CCPoint centerPos = CCPoint::CCPoint(visblesize.width/2,visblesize.height/2);
CCPoint viewPos = ccpSub(centerPos, TagPos);
parent->setPosition(viewPos);
}
示例10: initWithLayers
bool CCScrollLayer::initWithLayers(CCArray * layers, float layerSize, int space)
{
if (CCLayer::init())
{
// Make sure the layer accepts touches
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,true);
currentScreen = 1;
// offset added to show preview of next/previous screens
scrollWidth = (int)CCDirector::sharedDirector()->getWinSize().width;
scrollHeight = (int)CCDirector::sharedDirector()->getWinSize().height / 2;
CCAssert( (layerSize + space) <= scrollWidth, "Scroll width must be greater then layer width");
int layersInScreen = 0;
unsigned int i = 1;
while ((i<layers->count()) && ((layerSize + space) * i <= scrollWidth)) {
layersInScreen++;
i++;
}
startWidth = space/2;
scrollWidth = layersInScreen * (layerSize + space);
totalScreens = ceil(layers->count() / (float)layersInScreen);
for (i=0; i<layers->count(); i++)
{
CCLayer* l = (CCLayer *)layers->objectAtIndex(i);
l->setAnchorPoint(ccp(0, 0));
l->setPosition(ccp(startWidth + (layerSize + space) * i, scrollHeight-layerSize/2));
addChild(l);
}
return true;
}
else
{
return false;
}
}
示例11: setTowerLayer
void HelpScene::setTowerLayer(CCLayer* towerLayer){
CCSprite* bottom = SPRITE(bottom.png);
bottom->setPosition(ccp(VisibleRect::bottom().x,VisibleRect::bottom().y+35));
towerLayer->addChild(bottom);
GiantPageScrollView* towerPageScroll = GiantPageScrollView::create();
towerPageScroll->setPosition(VisibleRect::center());
towerPageScroll->cellSize = CCDirector::sharedDirector()->getWinSize();
towerPageScroll->tableSize = CCDirector::sharedDirector()->getWinSize();
towerPageScroll->cellNum = 18;
towerPageScroll->cells = CCArray::createWithCapacity(18);
for(int i=0;i<18;i++){
CCString* towerUrl;
CCString* towerInfo;
if(i<9){
towerUrl = CCString::createWithFormat("tower_0%d.png",i+1);
towerInfo = CCString::createWithFormat("tower_0%d_CN.png",i+1);
}else{
towerUrl = CCString::createWithFormat("tower_%d.png",i+1);
towerInfo = CCString::createWithFormat("tower_%d_CN.png",i+1);
}
CCLayer* towerLayer = CCLayer::create();
CCSprite* towerTxt = CCSprite::createWithSpriteFrameName(towerInfo->getCString());
CCSprite* tower = CCSprite::createWithSpriteFrameName(towerUrl->getCString());
tower->setPosition(VisibleRect::center());
towerTxt->setPosition(VisibleRect::center());
towerLayer->ignoreAnchorPointForPosition(false);
towerLayer->setPosition(VisibleRect::center());
towerLayer->addChild(tower);
towerLayer->addChild(towerTxt);
towerPageScroll->cells->addObject(towerLayer);
}
towerPageScroll->cells->retain();
towerLayer->addChild(towerPageScroll);
}
示例12: ccTouchMoved
void GiftListView::ccTouchMoved( CCTouch *pTouch, CCEvent *pEvent )
{
CCPoint touchPoint=pTouch->getLocation();
float nMovex = touchPoint.x - mMoveBeginPoint.x;
//CCLOG("movex:%f",nMovex);
mMovex += nMovex;
if (!(nMovex<5 && nMovex>-5))//移动
{
if (mNowSeledItem && mNowSeledItem->mStatus != GiftItem::nor)
{
mNowSeledItem->setStatus(GiftItem::nor);
mNowSeledItem = NULL;
}
}
CCLayer* firstPage = (CCLayer*)mPages.objectAtIndex(0);
CCLayer* lastPage = (CCLayer*)mPages.objectAtIndex(mPages.count()-1);
int f=0;//阻力
if (firstPage->getPositionX()>0 || lastPage->getPositionX()<0)//超出边界有阻力
{
f = nMovex/2;
}
for (int i=0;i<(int)mPages.count();i++)
{
CCLayer* page = (CCLayer*)mPages.objectAtIndex(i);
CCPoint curPoint = page->getPosition();
CCPoint nextPoint = ccp(curPoint.x+nMovex-f,curPoint.y);
page->setPosition(nextPoint);
}
mMoveBeginPoint.setPoint(touchPoint.x,touchPoint.y);
}
示例13: addPage
CCLayer* GiftListView::addPage()
{
CCLayer* page = CCLayer::create();
page->setAnchorPoint(ccp(0,0));
mPages.addObject(page);
page->setContentSize(getContentSize());
float pageX=0;
if (mPageTotal!=0)
pageX = ((CCLayer*)mPages.objectAtIndex(mPageTotal-1))->getPositionX()+page->getContentSize().width + mPageInterval;
page->setPosition(ccp(pageX,0));
addChild(page);
mPageTotal++;
GiftPageMarker* marker = NULL;
if (mMarkerImgPath=="" && mMarkerDisImgPath=="")
marker = GiftPageMarker::create("spot_highlight.png","spot_dark.png");
else
marker = GiftPageMarker::create(mMarkerImgPath.c_str(),mMarkerDisImgPath.c_str());
mPageMarkers.addObject(marker);
for (int i=0;i<(int)mPageMarkers.count();i++)
{
GiftPageMarker* markertmp = (GiftPageMarker*)mPageMarkers.objectAtIndex(i);
int minterval = 7;
int mw = markertmp->mMenuItem->getContentSize().width;
int mx = i*(mw + minterval)+ getContentSize().width/2 - (mPageTotal-1)*(mw + minterval)/2 + mMarkPosOffset.x;
int my = -7 - mItemIntervalV+mMarkPosOffset.y;
markertmp->setPosition(ccp(mx,my));
}
addChild(marker);
setPageMarkerShow(1);
return page;
}
示例14: MakeScroll
void CocoRoomTodayCandy::MakeScroll()
{
int numOfList = friendList.size();
// init select array
selected.clear();
for (int i = 0 ; i < numOfList ; i++)
selected.push_back(false);
// make scroll
scrollContainer = CCLayer::create();
scrollContainer->setPosition(ccp(77, 492+904+243));
//scrollContainer->setContentSize(CCSizeMake(862, (numOfList-1)*166));
int height = 0;
char fname[50], fname2[50];
for (int i = numOfList-1 ; i >= 0 ; i--)
{
if (friendList[i]->GetKakaoId() == myInfo->GetKakaoId())
continue;
CCLayer* itemLayer = CCLayer::create();
itemLayer->setContentSize(CCSizeMake(862, 166));
//itemLayer->setPosition(ccp(34, (numOfList-1-height)*166));
itemLayer->setPosition(ccp(34, height*166));
scrollContainer->addChild(itemLayer, 2);
spriteClass->layers.push_back(itemLayer);
height++;
// 프로필 이미지
sprintf(fname, "background/bg_profile.png%d", i);
ProfileSprite* psp = ProfileSprite::GetObj(friendList[i]->GetImageUrl());
if (friendList[i]->GetImageUrl() != "" && psp->IsLoadingDone())
{
spriteClass->spriteObj.push_back( SpriteObject::CreateFromSprite(0, psp->GetProfile(), ccp(0, 0), ccp(35+5, 35+11), CCSize(0,0), "", "Layer", itemLayer, 3, 0, 255, 0.95f) );
sprintf(fname, "background/bg_profile.png%d", i);
spriteClass->spriteObj.push_back( SpriteObject::Create(0, fname, ccp(0, 0), ccp(35, 35), CCSize(0, 0), "", "Layer", itemLayer, 3) );
}
else
{
spriteClass->spriteObj.push_back( SpriteObject::CreateFromSprite(0, psp->GetProfile(), ccp(0, 0), ccp(35, 35), CCSize(0,0), "", "Layer", itemLayer, 3, 0, 255, 1.0f, -888*(numOfList-i)) ); // tag = -888 * (i+1)
spriteClass->spriteObj.push_back( SpriteObject::Create(0, fname, ccp(0, 0), ccp(35, 35), CCSize(0, 0), "", "Layer", itemLayer, 3, 0, 255, -777*(numOfList-i)) ); // tag = -777 * (i+1)
}
// name (text)
spriteClass->spriteObj.push_back( SpriteObject::CreateLabel(friendList[i]->GetNickname(), fontList[0], 48, ccp(0, 0), ccp(196, 71), ccc3(78,47,8), "", "Layer", itemLayer, 3) );
// button
sprintf(fname, "button/btn_blue_mini.png%d", i);
spriteClass->spriteObj.push_back( SpriteObject::Create(0, fname, ccp(0, 0), ccp(635, 34+3), CCSize(0, 0), "", "Layer", itemLayer, 3, 0, 255) );
sprintf(fname2, "letter/letter_select.png%d", i);
spriteClass->spriteObj.push_back( SpriteObject::Create(0, fname2, ccp(0.5, 0), ccp(spriteClass->spriteObj[spriteClass->spriteObj.size()-1]->sprite->getContentSize().width/2, 24), CCSize(0, 0), fname, "0", NULL, 3, 1, 255) );
/*if (friendList[i]->GetPotionMsgStatus() == 0)
{
((CCSprite*)spriteClass->FindSpriteByName(fname))->setColor(ccc3(150,150,150));
((CCSprite*)spriteClass->FindSpriteByName(fname2))->setColor(ccc3(150,150,150));
}*/
sprintf(fname, "button/btn_skill_master.png%d", i);
spriteClass->spriteObj.push_back( SpriteObject::Create(0, fname, ccp(0, 0), ccp(635, 34+6), CCSize(0, 0), "", "Layer", itemLayer, 3, 0, 0) );
sprintf(fname2, "letter/letter_select_brown.png%d", i);
spriteClass->spriteObj.push_back( SpriteObject::Create(0, fname2, ccp(0.5, 0), ccp(spriteClass->spriteObj[spriteClass->spriteObj.size()-1]->sprite->getContentSize().width/2, 27), CCSize(0, 0), fname, "0", NULL, 3, 1, 0) );
SetSelectMode(i);
// dotted line
//if (i < numOfList-1)
//{
sprintf(fname, "background/bg_dotted_line.png%d", i);
spriteClass->spriteObj.push_back( SpriteObject::Create(0, fname, ccp(0, 0), ccp(0, 5), CCSize(0, 0), "", "Layer", itemLayer, 3) );
//}
}
// container 생성 + offset
scrollContainer->setContentSize(CCSizeMake(862, height*166));
scrollView->setContainer(scrollContainer);
scrollView->setContentSize(scrollContainer->getContentSize());
scrollView->setContentOffset(ccp(0, scrollView->minContainerOffset().y), false);
}
示例15: init
bool ScrollScene::init()
{
if ( !RecipeBase::init() )
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCLayer* scrollContainer = CCLayer::create(); // Container for the scroll view
scrollContainer->setAnchorPoint(CCPointZero); // CCScrollView does this too when it's set as the container.
CCLayerColor* panelBg = CCLayerColor::create(ccc4(51, 51, 51, 255),640,2000);
panelBg->setPosition(ccp(0,0));
scrollContainer->addChild(panelBg,2);
// Content for the container
CCSprite *tallContentA = CCSprite::create("image/quest/05ev_210222.png");
tallContentA ->setPosition(ccp(winSize.width*0.5f, 700));
CCSprite *tallContentB = CCSprite::create("image/quest/07ev_210232.png");
tallContentB ->setPosition(ccp(winSize.width*0.5f, 200));
CCSprite *tallContentC = CCSprite::create("image/quest/07ev_210232.png");
tallContentC ->setPosition(ccp(winSize.width*0.5f, 900));
CCSprite *tallContentD = CCSprite::create("image/quest/07ev_210232.png");
tallContentD ->setPosition(ccp(winSize.width*0.5f, 1400));
scrollContainer->addChild(tallContentA, 2);
scrollContainer->addChild(tallContentB, 2);
scrollContainer->addChild(tallContentC, 2);
scrollContainer->addChild(tallContentD, 2);
float scrollContainerHeight = tallContentA->getContentSize().height + tallContentB->getContentSize().height;
scrollContainer->setPosition(CCPointZero);
scrollContainer->setContentSize(CCSizeMake(640, 2000));
// Set up scroll view
cocos2d::extension::CCScrollView* scrollView = cocos2d::extension::CCScrollView::create(ccp(640, 960), scrollContainer);
scrollView->setPosition(ccp(0, 100));
scrollView->setDirection(cocos2d::extension::kCCScrollViewDirectionVertical);
// ScrollView initializes at the (left, bottom). The container also gets positioned relative to that and goes Y-up.
// Pre-set it to the value CCScrollView::minContainerOffset will return when it's scrolled to the top
// (note, this is a negative number, indicating the touch moving downwards, i.e. it's pre-scrolled such that the top of the content is visible when we begin)
scrollView->setContentOffset(ccp(0, 0));
CCLOG("test : %f",winSize.height-scrollContainerHeight*1.05f);
/*
// (StackOverflow Post Edit: This hack is not required.)
// Hack: CCScrollView's maxContainerOffset is (0, 0) and minContainerOffset is (difference between view and content size which is negative)
// It's designed to be (left, bottom) based and positive scrolling means showing stuff above the top of the screen.
// Since we're using it in terms of Window coordinates ((left, top) based), we scale the scroll view
// and it's container's children by -1 and position the children differently
// (eg. Y position winSize.height*0.1f was changed to winSize.height*0.9f)
// We can't just set the scroll view's Y scale to -1 because CCNode::getScale asserts that X and Y scale must be the same.
scrollView->setScale(-1.f);
tallContentA->setScale(-1.f);
tallContentB->setScale(-1.f);
*/
this->addChild(scrollView);
return true;
}