本文整理汇总了C++中CCMenuItemFont::setAnchorPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemFont::setAnchorPoint方法的具体用法?C++ CCMenuItemFont::setAnchorPoint怎么用?C++ CCMenuItemFont::setAnchorPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemFont
的用法示例。
在下文中一共展示了CCMenuItemFont::setAnchorPoint方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool HelloWorld::init()
{
if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) ) {
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCSprite* bg = CCSprite::create("bg.png");
bg->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2));
this->addChild(bg, 0, 0);
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
CCMenuItemFont* sBtn = CCMenuItemFont::create("", this, menu_selector(HelloWorld::btnCB));
sBtn->setTag(SBTNTAG);
sBtn->setAnchorPoint(CCPointZero);
sBtn->setPosition(50, 200);
sBtn->setColor(ccRED);
CCMenuItemFont* rbtn = CCMenuItemFont::create("", this, menu_selector(HelloWorld::btnCB));
rbtn->setTag(RTBTNTAG);
rbtn->setAnchorPoint(CCPointZero);
rbtn->setPosition(50, 300);
rbtn->setColor(ccGREEN);
// create menu, it's an autorelease object
pMenu = CCMenu::create(pCloseItem, sBtn, rbtn, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
// show filter node
this->setAnchorPoint(CCPointZero);
fnode = GaussianBlur::screenBlurNodeInstance();
fnode->reset(this);
this->addChild(fnode);
updateBtn(SBTNTAG);
updateBtn(RTBTNTAG);
return true;
}
示例2: createPauseLayer
void GameLayer::createPauseLayer() {
Context *context = Context::sharedContext();
CCSize s = CCDirector::sharedDirector()->getWinSize();
/* 半透明层 */
CCLayerColor* pauseLayer = CCLayerColor::create();
pauseLayer->setContentSize(CCSizeMake(s.width, s.height));
pauseLayer->setColor(ccc3(0, 0, 0));
pauseLayer->setOpacity(150);
CCMenu *menu = CCMenu::create();
//回到游戏
CCMenuItemImage *resumebg = CCMenuItemImage::create(("btn_big.png"),
("btn_big.png"));
resumebg->setTarget(this, menu_selector(GameLayer::onResumeItem));
CCMenuItemFont *resumetxt = CCMenuItemFont::create(LOCAL_RESOURCES->valueByKey("i18n_resume")->getCString());
resumebg->setAnchorPoint(ccp(0.5, 0.5));
resumebg->setPosition(ccpp(0, 0));
resumetxt->setPosition(
ccp(resumebg->getContentSize().width / 2,
resumebg->getContentSize().height / 2));
resumetxt->setAnchorPoint(ccp(0.5, 0.5));
resumetxt->setColor(context->getFontColor());
resumebg->addChild(resumetxt);
menu->addChild(resumebg);
//回到菜单
CCMenuItemImage *backbg = CCMenuItemImage::create(("btn_big.png"),
("btn_big.png"));
backbg->setTarget(this, menu_selector(GameLayer::onBackItem));
CCMenuItemFont *backtxt = CCMenuItemFont::create(LOCAL_RESOURCES->valueByKey("i18n_back")->getCString());
backbg->setAnchorPoint(ccp(0.5, 0.5));
backbg->setPosition(ccpp(0, -0.12));
backtxt->setPosition(
ccp(backbg->getContentSize().width / 2,
backbg->getContentSize().height / 2));
backtxt->setAnchorPoint(ccp(0.5, 0.5));
backtxt->setColor(context->getFontColor());
backbg->addChild(backtxt);
menu->addChild(backbg);
pauseLayer->addChild(menu);
CCDirector::sharedDirector()->getRunningScene()->addChild(pauseLayer, 0,
TAG_LAYER_PAUSE);
}
示例3: actionOption
/* Action option callback */
void LuaDecisionTree::actionOption(CCString* str) {
CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(16);
optionsOnScreen += 1;
//Add action option to screen
CCString *optionStr = CCString::createWithFormat("[%s)", str);
CCMenuItemFont *optionItem = CCMenuItemFont::create(str->getCString() , this , menu_selector(LuaDecisionTree::selectOption));
optionItem->setTag(optionsOnScreen);
optionItem->setPosition(ccp(10,135 - optionsOnScreen*20));
optionItem->setAnchorPoint(ccp(0,1));
CCMenu *menu = CCMenu::createWithItem(optionItem);
menu->setPosition(ccp(0,0));
optionsNode->addChild(menu);
}
示例4: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize aScreenSize = CCDirector::sharedDirector()->getWinSize();
// background
CCLayerColor* aBackground = CCLayerColor::create(ccc4(128, 128, 128, 255), aScreenSize.width, aScreenSize.height);
this->addChild(aBackground);
std::string anAnimFileFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("basic_transform.sam");
mAnimNode = SuperAnim::SuperAnimNode::create(anAnimFileFullPath, 0, this);
mAnimNode->setPosition(CCPointMake(aScreenSize.width * 0.5f, aScreenSize.height * 0.5f));
this->addChild(mAnimNode);
mAnimNode->PlaySection("mixed");
// add a menu item to next sample
CCMenuItemFont* aNextSampleMenuItem = CCMenuItemFont::create("Next Scene", this, menu_selector(HelloWorld::menuCallback));
aNextSampleMenuItem->setAnchorPoint(CCPointMake(1.0f, 0.0f));
aNextSampleMenuItem->setPosition(CCPointMake(aScreenSize.width, 0.0f));
CCMenu* aMenu = CCMenu::createWithItem(aNextSampleMenuItem);
this->addChild(aMenu);
aMenu->setPosition(CCPointZero);
// add a title
CCLabelTTF* aTitle = CCLabelTTF::create("basic animation", "", 16);
aTitle->setAnchorPoint(CCPointMake(0.5f, 1.0f));
aTitle->setPosition(CCPointMake(aScreenSize.width * 0.5f, aScreenSize.height));
this->addChild(aTitle);
return true;
}
示例5: init
bool RequestList::init()
{
if ( !CCLayer::init())
{
return false;
}
mPhotoLoadIndex = 0;
EziSocialObject::sharedObject()->setFacebookDelegate(this);
CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
SCREEN_WIDTH = winSize.width;
SCREEN_HEIGHT = winSize.height;
CCLayerColor *backgroundLayer = CCLayerColor::create(ccc4(20, 100, 100, 255), SCREEN_WIDTH, SCREEN_HEIGHT);
this->addChild(backgroundLayer);
MENU_FONT_SCALE = SCREEN_HEIGHT/320;
// Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(RequestList::showHomePage));
itemBack->setAnchorPoint(ccp(1, 0.5));
itemBack->setPosition(ccp(SCREEN_WIDTH - 10, (itemBack->getContentSize().height/2 + 2) * MENU_FONT_SCALE));
CCMenuItemFont *purgeItems = CCMenuItemFont::create("Clear Completed Requests",
this,
menu_selector(RequestList::clearCompletedRequest));
purgeItems->setAnchorPoint(ccp(0, 0.5));
purgeItems->setPosition(ccp(10, (itemBack->getContentSize().height/2 + 2) * MENU_FONT_SCALE));
itemBack->setScale(MENU_FONT_SCALE);
purgeItems->setScale(MENU_FONT_SCALE);
CCMenu *menuBack = CCMenu::create(itemBack, purgeItems, NULL);
menuBack->setPosition(CCPointZero);
addChild(menuBack);
float gap = itemBack->getContentSize().height * 2 * MENU_FONT_SCALE + (10 * MENU_FONT_SCALE);
_fbIncomingRequestList = NULL;
refreshList();
SCALE_FACTOR = SCREEN_HEIGHT / 768.0f;
SCALE_FACTOR = MAX(0.5, SCALE_FACTOR);
PHOTO_SCALE = SCREEN_HEIGHT/1536;
if (PHOTO_SCALE <= 0.5 && PHOTO_SCALE > 0.25)
{
FB_DEFAULT_PHOTO = "fb_user_icon_half.jpg";
}
else if (PHOTO_SCALE < 0.25)
{
FB_DEFAULT_PHOTO = "fb_user_icon_quater.jpg";
}
CCSprite *sprite = CCSprite::create(FB_DEFAULT_PHOTO);
CELL_HEIGHT = (sprite->getContentSize().height) + (40 * PHOTO_SCALE);
mTableView = CCTableView::create(this, CCSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - gap));
mTableView->setDirection(kCCScrollViewDirectionVertical);
mTableView->setPosition(ccp(0, gap/2));
mTableView->setDelegate(this);
this->addChild(mTableView);
mTableView->reloadData();
ALL_DOWNLOAD_COMPLETE = true;
mLoadingImage = CCSprite::create("ball.png");
mLoadingImage->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2));
mLoadingImage->retain();
this->addChild(mLoadingImage);
this->hideLoadingAction();
return true;
}
示例6: init
bool FriendList::init()
{
if ( !CCLayer::init())
{
return false;
}
mEnableHighScoreDisplay = false;
mEnableInstalledDisplay = false;
mReadyForNextDownload = false;
mPhotoLoadIndex = 0;
EziSocialObject::sharedObject()->setFacebookDelegate(this);
CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
SCREEN_WIDTH = winSize.width;
SCREEN_HEIGHT = winSize.height;
CCLayerColor *backgroundLayer = CCLayerColor::create(ccc4(20, 100, 100, 255), SCREEN_WIDTH, SCREEN_HEIGHT);
this->addChild(backgroundLayer);
MENU_FONT_SCALE = SCREEN_HEIGHT/320;
// Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(FriendList::showHomePage));
itemBack->setPosition(ccp(SCREEN_WIDTH/2, (itemBack->getContentSize().height/2 + 2) * MENU_FONT_SCALE));
CCMenuItemFont *itemHighScore = CCMenuItemFont::create("High Scores", this, menu_selector(FriendList::showHighScoreList));
itemHighScore->setAnchorPoint(ccp(1, 0.5));
itemHighScore->setPosition(ccp((SCREEN_WIDTH-10), itemBack->getPositionY()));
CCMenuItemFont *allFriends = CCMenuItemFont::create("All Friends", this, menu_selector(FriendList::showAllFriendsList));
allFriends->setAnchorPoint(ccp(0, 0.5));
allFriends->setPosition(ccp((10), itemBack->getPositionY()));
CCMenuItemFont *installedOnly = CCMenuItemFont::create("Installed Only", this, menu_selector(FriendList::showInstalledList));
installedOnly->setAnchorPoint(ccp(0, 1));
installedOnly->setPosition(ccp((10), SCREEN_HEIGHT - 2));
CCMenuItemFont *notPlaying = CCMenuItemFont::create("Friends Not Playing", this, menu_selector(FriendList::showNotInstalledList));
notPlaying->setAnchorPoint(ccp(1, 1));
notPlaying->setPosition(ccp((SCREEN_WIDTH-10), SCREEN_HEIGHT - 2));
itemBack->setScale(MENU_FONT_SCALE);
itemHighScore->setScale(MENU_FONT_SCALE);
allFriends->setScale(MENU_FONT_SCALE);
installedOnly->setScale(MENU_FONT_SCALE);
notPlaying->setScale(MENU_FONT_SCALE);
CCMenu *menuBack = CCMenu::create(itemBack, itemHighScore, allFriends, installedOnly, notPlaying, NULL);
menuBack->setPosition(CCPointZero);
addChild(menuBack);
float gap = itemBack->getContentSize().height * 2 * MENU_FONT_SCALE + (10 * MENU_FONT_SCALE);
mFriendList = NULL;
PHOTO_SCALE = SCREEN_HEIGHT/1536;
if (PHOTO_SCALE <= 0.5 && PHOTO_SCALE > 0.25)
{
FB_DEFAULT_PHOTO = "fb_user_icon_half.jpg";
}
else if (PHOTO_SCALE < 0.25)
{
FB_DEFAULT_PHOTO = "fb_user_icon_quater.jpg";
}
CCSprite *sprite = CCSprite::create(FB_DEFAULT_PHOTO);
CELL_HEIGHT = (sprite->getContentSize().height) + (40 * PHOTO_SCALE);
mTableView = CCTableView::create(this, CCSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - gap));
mTableView->setDirection(kCCScrollViewDirectionVertical);
mTableView->setPosition(ccp(0, gap/2));
mTableView->setDelegate(this);
this->addChild(mTableView);
mTableView->reloadData();
ALL_DOWNLOAD_COMPLETE = true;
mLoadingImage = CCSprite::create("ball.png");
mLoadingImage->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2));
mLoadingImage->retain();
this->addChild(mLoadingImage);
this->hideLoadingAction();
return true;
}
示例7: init
// 主菜单Layer对象创建时初始化, 用来完成布局主菜单的功能。 包括背景图片、菜单、背景音乐加载等。
bool MainMenu::init()
{
int remainder; // 菜单顶部空白
int divider; // 菜单间空白
int halfWidth;
// 必须先执行基类的方法
if(!CCLayer::init())
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
halfWidth = winSize.width / 2;
// 添加背景图片,放在最底层
CCSprite* background = CCSprite::create("background.png");
background->setPosition(ccp(halfWidth, winSize.height / 2));
addChild(background, 0);
CCSprite* title = CCSprite::create("title.png");
title->setAnchorPoint(ccp(0.5, 1));
title->setScale(0.5);
title->setPosition(ccp(halfWidth, winSize.height - 20));
addChild(title, 10);
// 添加菜单
CCMenuItemFont* startGame = CCMenuItemFont::create("start", this, menu_selector(MainMenu::startGame));
CCSize contentSize = startGame->getContentSize();
divider = contentSize.height; // 菜单间间隔单项高度的1/3
remainder = (winSize.height - divider * MAIN_MENU_NUM) * 3 / 5;
startGame->setAnchorPoint(ccp(0.5, 1));
startGame->setPosition(ccp(halfWidth, winSize.height - remainder));
startGame->setEnabled(false);
CCMenuItemFont* pauseGame = CCMenuItemFont::create("pause", this, menu_selector(MainMenu::pauseGame));
pauseGame->setAnchorPoint(ccp(0.5, 1));
pauseGame->setPosition(ccp(halfWidth, winSize.height - remainder - divider));
pauseGame->setEnabled(false);
pauseGame->setVisible(true);
CCMenuItemFont* resumeGame = CCMenuItemFont::create("resume", this, menu_selector(MainMenu::resumeGame));
resumeGame->setAnchorPoint(ccp(0.5, 1));
resumeGame->setPosition(ccp(halfWidth, winSize.height - remainder - divider));
resumeGame->setEnabled(false);
resumeGame->setVisible(false);
CCMenuItemFont* setting = CCMenuItemFont::create("setting", this, menu_selector(MainMenu::setting));
setting->setAnchorPoint(ccp(0.5, 1));
setting->setPosition(ccp(halfWidth, winSize.height - remainder - 2 * divider));
setting->setEnabled(false);
CCMenuItemFont* quit = CCMenuItemFont::create("quit", this, menu_selector(MainMenu::quit));
quit->setAnchorPoint(ccp(0.5, 1));
quit->setPosition(ccp(halfWidth, winSize.height - remainder - 3 * divider));
quit->setEnabled(false);
CCMenu* mainMenu = CCMenu::create(startGame, pauseGame, resumeGame, setting, quit, NULL);
mainMenu->setPosition(CCPointZero);
addChild(mainMenu, 11, MAIN_MENU_TAG);
// 对背景音乐进行预加载及设置, 默认背景音乐开启
isSound = true;
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathForFilename("background.mp3")).c_str());
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathForFilename("background.mp3")).c_str(), true);
return true;
}
示例8: okCallback
void HelloWorld::okCallback(CCObject* pSender)
{
if(!m_bg)
{
m_runLayer = CCLayer::create();
this->addChild(m_runLayer);
int dirSel = m_dirSelItem->getSelectedIndex();
switch (dirSel)
{
case 0:
m_bg = ScrollingBackground::create(SD_RIGHT_TO_LEFT);
m_direction = SD_RIGHT_TO_LEFT;
break;
case 1:
m_bg = ScrollingBackground::create(SD_LEFT_TO_RIGHT);
m_direction = SD_LEFT_TO_RIGHT;
break;
case 2:
m_bg = ScrollingBackground::create(SD_TOP_TO_BOTTOM);
m_direction = SD_TOP_TO_BOTTOM;
break;
case 3:
m_bg = ScrollingBackground::create(SD_BOTTOM_TO_TOP);
m_direction = SD_BOTTOM_TO_TOP;
break;
default:
break;
}
m_runLayer->addChild(m_bg,1);
for (int i = 1; i < 5; i++)
{
addBgSprite(i);
}
//当有一个背景精灵彻底离开屏幕的时候的消息
if(m_modeSelItem->getSelectedIndex()==0)
m_bg->setBgChangeEventListener(this,bgSpriteChangeEvent(HelloWorld::loopBgChangeCallback)); //循环模式
else
m_bg->setBgChangeEventListener(this,bgSpriteChangeEvent(HelloWorld::dropBgChangeCallback)); //丢弃模式
//当背景精灵移动时候的消息
m_bg->setBgMoveEventListener(this,bgSpriteMoveEvent(HelloWorld::bgMoveCallback));
m_velocity = 300.0f;
m_bgSprite = m_bg->getCurBgSprite();
m_bg->beginContinuousScroll(m_velocity);
//一个跟随背景移动的物体
m_pItem = CCSprite::create("item.png");
m_pItem->setAnchorPoint(ccp(0.5f,0.5f));
m_pItem->setPosition(ccp(0.0f,0.0f));
m_runLayer->addChild(m_pItem,2);
//pItem锚点一直都是(0.5,0.5),坐标一直是(0.0,0.0),注意看当画面切换的时候他会出现在哪里
//背景精灵精灵的锚点不同,会影响pItem的位置
m_pItem->setPosition(m_bg->getCurBgSprite()->getPosition());
/*下面的是一些菜单的设置,不看也可以*/
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//返回按钮
CCMenuItemFont* back = CCMenuItemFont::create("back",this,menu_selector(HelloWorld::backCallback));
back->setAnchorPoint(ccp(1.0f,1.0f));
back->setPosition(ccp(visibleSize.width/2.0f,visibleSize.height/2.0f));
//设置相反速度的按钮
CCMenuItemFont* reverse = CCMenuItemFont::create("reverse",this,menu_selector(HelloWorld::reverseCallback));
//暂停
CCMenuItemToggle* pause = CCMenuItemToggle::createWithTarget(this,
menu_selector(HelloWorld::pauseCallback),
CCMenuItemFont::create("pause"),
CCMenuItemFont::create("resume"),
NULL);
pause->setPosition(ccp(0.0f,50.0f));
//上一个画面
CCMenuItemImage* lastBg = CCMenuItemImage::create("lastBgNor.png","lastBgCli.png",0,this,menu_selector(HelloWorld::nextBgCallback));
lastBg->setTag(0);
lastBg->setAnchorPoint(ccp(0.0f,0.5f));
lastBg->setPosition(ccp(-visibleSize.width/2.0f,0.0f));
//下一个画面
CCMenuItemImage* nextBg = CCMenuItemImage::create("NextBgNor.png","NextBgCli.png",0,this,menu_selector(HelloWorld::nextBgCallback));
nextBg->setTag(1);
nextBg->setAnchorPoint(ccp(1.0f,0.5f));
nextBg->setPosition(ccp(visibleSize.width/2.0f,0.0f));
//增加背景精灵
CCMenuItemFont* add = CCMenuItemFont::create("add background",this,menu_selector(HelloWorld::addBgSpriteCallback));
add->setPosition(ccp(0.0f,-50.0f));
CCMenu* pMenu = CCMenu::create(pause,reverse,add,lastBg,nextBg,back,NULL);
//.........这里部分代码省略.........