本文整理汇总了C++中MenuItemLabel类的典型用法代码示例。如果您正苦于以下问题:C++ MenuItemLabel类的具体用法?C++ MenuItemLabel怎么用?C++ MenuItemLabel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MenuItemLabel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: menuEventCallback
void HelloWorld::menuEventCallback(cocos2d::Ref* pSender){
MenuItemLabel* pMenuItem = (MenuItemLabel*)pSender;
char buf[64];
int i = pMenuItem->getTag();
sprintf(buf, s_EventMenuItem[i].id.c_str(), ++_indexes[i]);
LabelTTF* label = (LabelTTF*)pMenuItem->getLabel();
label->setString(buf);
switch (i) {
case CREATE_USER_ID:
mTDGAaccount = TDCCAccount::setAccount(label->getString().c_str());
break;
case ADD_LEVEL:
if (mTDGAaccount) mTDGAaccount->setLevel(_indexes[i]);
break;
case UPDATE_GAME_SERVER:
if (mTDGAaccount) mTDGAaccount->setGameServer(label->getString().c_str());
break;
case UPDATE_USER_NAME:
if (mTDGAaccount) mTDGAaccount->setAccountName(label->getString().c_str());
break;
case UPDATE_GENDER:
if (mTDGAaccount) mTDGAaccount->setGender(mTDGAaccount->kGenderMale);
break;
case UPDATE_TYPE:
if (mTDGAaccount) mTDGAaccount->setAccountType(mTDGAaccount->kAccountType1);
break;
default:
break;
}
}
示例2: CC_CALLBACK_1
bool MenuScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
m_menu = Menu::create();
m_menu->setPosition(Point::ZERO);
this->addChild(m_menu);
for (size_t i = 0; i < g_fractals_size; ++i)
{
LabelTTF * label = LabelTTF::create(g_fractals[i].fractal_name, "fonts/Marker Felt.ttf", 24);
MenuItemLabel * menuItem = MenuItemLabel::create(label, CC_CALLBACK_1(MenuScene::menuCallback, this));
menuItem->setPosition(Point(VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE)));
m_menu->addChild(menuItem, i);
}
EventListenerTouchOneByOne * touchListener = EventListenerTouchOneByOne::create();
touchListener->setSwallowTouches(true);
touchListener->onTouchBegan = CC_CALLBACK_2(MenuScene::onTouchBegan, this);
touchListener->onTouchMoved = CC_CALLBACK_2(MenuScene::onTouchMoved, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this);
EventListenerMouse * mouseListener = EventListenerMouse::create();
mouseListener->onMouseScroll = CC_CALLBACK_1(MenuScene::onMouseScroll, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(mouseListener, this);
return true;
}
示例3: CC_CALLBACK_0
bool MenuLayer::init(){
if (!Layer::init())
{
return false;
}
GameUtile::Pause();
m_visibleSize = Director::getInstance()->getVisibleSize();
//Ìí¼Ómenu°´Å¥
Label* labelSave = Label::create("Save", "Comic Sans MS", 30);
MenuItemLabel* menuSave = MenuItemLabel::create(labelSave, CC_CALLBACK_0(MenuLayer::saveGame, this));
menuSave->setPosition(Vec2(m_visibleSize.width * 0.5, m_visibleSize.height * 0.7));
Label* labelRead = Label::create("Read", "Comic Sans MS", 30);
MenuItemLabel* menuRead = MenuItemLabel::create(labelRead, CC_CALLBACK_0(MenuLayer::readGame, this));
menuRead->setPosition(Vec2(m_visibleSize.width * 0.5, m_visibleSize.height * 0.6));
Label* labelMusic = Label::create("Muisc", "Comic Sans MS", 30);
global->uiLayer->addChild(labelMusic, 110);
Label* labelON = Label::create("ON", "Comic Sans MS", 30);
Label* labelOFF = Label::create("OFF", "Comic Sans MS", 30);
MenuItemLabel* menuMusic0 = MenuItemLabel::create(labelON, CC_CALLBACK_0(MenuLayer::musicON, this));
MenuItemLabel* menuMusic1 = MenuItemLabel::create(labelOFF, CC_CALLBACK_0(MenuLayer::musicOFF, this));
menuMusic0->setPosition(Vec2(m_visibleSize.width * 0.5, m_visibleSize.height * 0.5));
menuMusic1->setPosition(Vec2(m_visibleSize.width * 0.6, m_visibleSize.height * 0.5));
Label* labelReturn = Label::create("Return", "Comic Sans MS", 30);
MenuItemLabel* menuReturn = MenuItemLabel::create(labelReturn, CC_CALLBACK_0(MenuLayer::returnGame, this));
menuReturn->setPosition(Vec2(m_visibleSize.width * 0.5, m_visibleSize.height * 0.4));
Label* labelExit = Label::create("Exit Game", "Comic Sans MS", 30);
MenuItemLabel* menuExit = MenuItemLabel::create(labelExit, CC_CALLBACK_0(MenuLayer::exitGame, this));
menuExit->setPosition(Vec2(m_visibleSize.width * 0.5, m_visibleSize.height * 0.3));
Menu* menu0 = Menu::create(menuSave, menuRead, menuMusic0, menuMusic1, menuReturn, menuExit, NULL);
menu0->setPosition(Vec2::ZERO);
global->uiLayer->addChild(menu0, 110);
menu0->setTag(0);
return true;
}
示例4: BeginGame
void ShowHeroScene::CreateMenu()
{
auto strings = FileUtils::getInstance()->getValueMapFromFile("fonts/menu.xml");
std::string strBeginGame = strings["BeginGame"].asString();
std::string strCreateGame = strings["CreateGame"].asString();
std::string strJoinGame = strings["JoinGame"].asString();
std::string strExitGame = strings["ExitGame"].asString();
if (/*GameLogic::GetInstance()->IsSingleGame()*/GameLogic::GetInstance()->GetGameType() == SINGLE_GAME_TYPE)
{
MenuItemLabel* beginGameItem = MenuItemLabel::create(LabelTTF::create(strBeginGame, "Arial", 40),
[&](Ref* sender)
{
BeginGame();
}
);
beginGameItem->setPosition(Point(500,100));
auto menu = Menu::create(beginGameItem,NULL);
menu->setPosition(Point(0, 0));
addChild(menu);
}
else
{
if (/*GameLogic::GetInstance()->IsCreator()*/GameLogic::GetInstance()->GetGameType() == CREATE_GAME_TYPE)
{
MenuItemLabel* createGameItem = MenuItemLabel::create(LabelTTF::create(strCreateGame, "Arial", 40),
[&](Ref* sender)
{
CreateGame();
}
);
createGameItem->setPosition(Point(500,100));
auto menu = Menu::create(createGameItem,NULL);
menu->setPosition(Point(0, 0));
addChild(menu);
}
else
{
MenuItemLabel* joinGameItem = MenuItemLabel::create(LabelTTF::create(strJoinGame, "Arial", 40),
[&](Ref* sender)
{
JoinGame();
}
);
joinGameItem->setPosition(Point(500,100));
auto menu = Menu::create(joinGameItem,NULL);
menu->setPosition(Point(0, 0));
addChild(menu);
}
}
}
示例5: ttfConfig2
bool GameMenu::init(void)
{
Size sizeWin = Director::getInstance()->getWinSize();
Menu* pItemMenu = Menu::create();
//TTFConfig ttfConfig(CF_F("fonts_en").c_str(), 48);
TTFConfig ttfConfig2(CF_F("fonts_cn").c_str(), CF_FT("font_menu"));
auto label = Label::createWithTTF(ttfConfig2, CF_S("label_normal_start"));
MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(GameMenu::menuNormalGameCallback, this));
auto labelInput = Label::createWithTTF(ttfConfig2, CF_S("label_login"));
MenuItemLabel* pMenuInput = MenuItemLabel::create(labelInput, CC_CALLBACK_1(GameMenu::menuUserLoginCallback, this));
auto labelLan = Label::createWithTTF(ttfConfig2, CF_S("label_net_start"));
MenuItemLabel* pMenuItemLanTest = MenuItemLabel::create(labelLan, CC_CALLBACK_1(GameMenu::menuNetGameCallback, this));
pItemMenu->addChild(pMenuItem);
pItemMenu->addChild(pMenuInput);
pItemMenu->addChild(pMenuItemLanTest);
pMenuItem->setPosition(0, sizeWin.height * CF_P("pos_main_start"));
pMenuInput->setPosition(0, sizeWin.height * CF_P("pos_main_login"));
pMenuItemLanTest->setPosition(0, sizeWin.height * CF_P("pos_main_netstart"));
pItemMenu->setPositionY(0);
this->addChild(pItemMenu);
MenuItemImage *pCloseItem = MenuItemImage::create(CF_F("image_closeNormal"), CF_F("image_closeSelect"),
CC_CALLBACK_1(GameMenu::menuCloseCallback, this));
Menu* pCloseMenu = Menu::create(pCloseItem, NULL);
pCloseMenu->setPositionY(sizeWin.height * CF_P("pos_main_close"));
this->addChild(pCloseMenu);
return true;
}
示例6: Vec2
void GameLayer::addScore()
{
// label2048
Label *_2048 = Label::createWithTTF("2048", "fonts/ClearSans-Bold.ttf", _visibleSize.width/5.9);
_2048->setColor(Color3B(121,110,100) );
_2048->setAnchorPoint(Vec2( 0, 0.5 ));
_2048->setPosition(Vec2( 0, _visibleSize.height-_2048->getContentSize().height/2) );
this->addChild(_2048);
// best score
DrawNode *bestscoreback = DrawNode::create();
bestscoreback->drawSolidRect( Vec2(-_visibleSize.width/6 ,-g_tileSize/3), Vec2(_visibleSize.width/6 ,g_tileSize/3), Color4F(Color3B(190,173,158)) );
bestscoreback->setPosition( Vec2(_visibleSize.width - _visibleSize.width/6-10 , _2048->getPositionY()-10 ) );
this->addChild(bestscoreback);
Label *best = Label::createWithTTF("BEST", "fonts/ClearSans-Bold.ttf", _visibleSize.width/25);
best->setColor(Color3B(240,228,216));
best->setPositionY(g_tileSize/6.5 );
bestscoreback->addChild(best);
sprintf(buff, "%d", Score::getInstance()->getTopScore());
bestscore = Label::createWithTTF(buff, "fonts/ClearSans-Bold.ttf", _visibleSize.width/15);
bestscore->setPositionY( -g_tileSize/7.5);
bestscoreback->addChild(bestscore);
//score
DrawNode *scoreback = DrawNode::create();
scoreback->drawSolidRect( Vec2(-_visibleSize.width/6 ,-g_tileSize/3), Vec2(_visibleSize.width/6 ,g_tileSize/3), Color4F(Color3B(190,173,158)) );
scoreback->setPosition( Vec2(_visibleSize.width - _visibleSize.width/6-10 , _2048->getPositionY() - g_tileSize/1 ) );
this->addChild(scoreback);
Label *sco = Label::createWithTTF("SCORE", "fonts/ClearSans-Bold.ttf", _visibleSize.width/25);
sco->setColor(Color3B(240,228,216));
sco->setPositionY(g_tileSize/6.5 );
scoreback->addChild(sco);
sprintf(buff, "%d", 0);
score = Label::createWithTTF(buff, "fonts/ClearSans-Bold.ttf", _visibleSize.width/15);
score->setPositionY( -g_tileSize/7.5);
scoreback->addChild(score);
// new game
DrawNode *newGame = DrawNode::create();
newGame->drawSolidRect( Vec2(-_visibleSize.width/6 ,-g_tileSize/4), Vec2(_visibleSize.width/6 ,g_tileSize/4), Color4F(Color3B(147,122,98)) );
newGame->setPosition( Vec2(_visibleSize.width/5.5 , _2048->getPositionY() - g_tileSize/1 ) );
this->addChild(newGame);
Label *ngame = Label::createWithTTF("New Game", "fonts/ClearSans-Bold.ttf", _visibleSize.width/17);
ngame->setColor(Color3B(250,246,241));
//newGame->addChild(ngame);
// ai
DrawNode *aiback = DrawNode::create();
aiback->drawSolidRect( Vec2(-_visibleSize.width/15 ,-g_tileSize/4), Vec2(_visibleSize.width/15 ,g_tileSize/4), Color4F(Color3B(147,122,98)) );
aiback->setPosition( Vec2(_visibleSize.width/2.3 , _2048->getPositionY() - g_tileSize/1 ) );
this->addChild(aiback);
Label *ai = Label::createWithTTF("AI", "fonts/ClearSans-Bold.ttf", _visibleSize.width/17);
ai->setColor(Color3B(250,246,241));
//aiback->addChild(ai);
MenuItemLabel *newgamelabel = MenuItemLabel::create(ngame, CC_CALLBACK_1(GameLayer::startNewGame, this));
newgamelabel->setPosition(newGame->getPosition());
ailable = MenuItemLabel::create(ai, CC_CALLBACK_1(GameLayer::startAi, this));
ailable->setPosition(aiback->getPosition());
Menu *menu = Menu::create(newgamelabel,ailable, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu);
}
示例7: eventMenuCallback
void TestAnalytics::eventMenuCallback(Object* pSender)
{
MenuItemLabel* pMenuItem = (MenuItemLabel*)pSender;
switch (pMenuItem->getTag())
{
case TAG_LOG_EVENT_ID:
{
_pluginAnalytics->logEvent("click");
_pluginAnalytics->logEvent("music");
}
break;
case TAG_LOG_EVENT_ID_KV:
{
LogEventParamMap paramMap;
paramMap.insert(LogEventParamPair("type", "popular"));
paramMap.insert(LogEventParamPair("artist", "JJLin"));
_pluginAnalytics->logEvent("music", ¶mMap);
}
break;
case TAG_LOG_ONLINE_CONFIG:
{
PluginParam param("abc");
log("Online config = %s", _pluginAnalytics->callStringFuncWithParam("getConfigParams", ¶m, NULL).c_str());
}
break;
case TAG_LOG_EVENT_ID_DURATION:
{
PluginParam event1("book");
PluginParam dura1(12000);
_pluginAnalytics->callFuncWithParam("logEventWithDuration", &event1, &dura1, NULL);
PluginParam event2("book");
PluginParam dura2(12000);
PluginParam label("chapter1");
_pluginAnalytics->callFuncWithParam("logEventWithDurationLabel", &event2, &dura2, &label, NULL);
PluginParam event3("music");
PluginParam dura3(2330000);
LogEventParamMap paramMap;
paramMap.insert(LogEventParamPair("type", "popular"));
paramMap.insert(LogEventParamPair("artist", "JJLin"));
PluginParam mapValue(paramMap);
_pluginAnalytics->callFuncWithParam("logEventWithDurationParams", &event3, &dura3, &mapValue, NULL);
}
break;
case TAG_LOG_EVENT_BEGIN:
{
_pluginAnalytics->logTimedEventBegin("music");
PluginParam event1("music");
PluginParam label1("one");
_pluginAnalytics->callFuncWithParam("logTimedEventWithLabelBegin", &event1, &label1, NULL);
PluginParam event2("music");
PluginParam label2("flag0");
LogEventParamMap paramMap;
paramMap.insert(LogEventParamPair("type", "popular"));
paramMap.insert(LogEventParamPair("artist", "JJLin"));
PluginParam mapValue(paramMap);
_pluginAnalytics->callFuncWithParam("logTimedKVEventBegin", &event2, &label2, &mapValue, NULL);
PluginParam event3("music-kv");
_pluginAnalytics->callFuncWithParam("logTimedEventBeginWithParams", &event3, &mapValue, NULL);
}
break;
case TAG_LOG_EVENT_END:
{
_pluginAnalytics->logTimedEventEnd("music");
PluginParam event1("music");
PluginParam label1("one");
_pluginAnalytics->callFuncWithParam("logTimedEventWithLabelEnd", &event1, &label1, NULL);
PluginParam event2("music");
PluginParam label2("flag0");
_pluginAnalytics->callFuncWithParam("logTimedKVEventEnd", &event2, &label2, NULL);
PluginParam event3("music-kv");
_pluginAnalytics->callFuncWithParam("logTimedEventEnd", &event3, NULL);
}
break;
case TAG_MAKE_ME_CRASH:
{
char* pNull = NULL;
*pNull = 0;
}
break;
default:
break;
}
}
示例8: Vec2
FailScene::FailScene(void)
{
Vec2 points[] = { Vec2(0, 0),
Vec2(0, 140),
Vec2(400, 140),
Vec2(400, 0) };
DrawNode* draw = DrawNode::create();
//±³¾°
draw->drawPolygon(points, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));
this->addChild(draw);
draw->setAnchorPoint(Point(.5, .5));
draw->setPositionX(ScreenUtil::getCenter().x - 200);
draw->setPositionY(ScreenUtil::getCenter().y - 140);
Vec2 points2[] = { Vec2(0, 0),
Vec2(0, 150),
Vec2(230, 150),
Vec2(230, 0) };
DrawNode* draw2 = DrawNode::create();
//±³¾°
draw2->drawPolygon(points2, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));
this->addChild(draw2);
draw2->setAnchorPoint(Point(.5, .5));
draw2->setPositionX(ScreenUtil::getCenter().x - 115);
draw2->setPositionY(ScreenUtil::getCenter().y + 40);
LabelTTF* scoreTxt = LabelTTF::create("Score:", "Arial", 45);
scoreTxt->setAnchorPoint(Point(0, .5));
scoreTxt->setPosition(Point(draw2->getPositionX() + 10,
draw2->getPositionY() + 110));
this->addChild(scoreTxt);
LabelTTF* bestScoreTxt = LabelTTF::create("Best:", "Arial", 45);
bestScoreTxt->setAnchorPoint(Point(0, .5));
bestScoreTxt->setPosition(Point(scoreTxt->getPositionX(),
draw2->getPositionY() + 50));
this->addChild(bestScoreTxt);
LabelTTF* scoreValTxt = LabelTTF::create("0", "Arial", 45);
scoreValTxt->setPositionX(scoreTxt->getPositionX() + scoreTxt->getContentSize().width + 25);
scoreValTxt->setPositionY(scoreTxt->getPositionY());
scoreValTxt->setTag(scoreValTxtTag);
this->addChild(scoreValTxt);
LabelTTF* bestScoreValTxt = LabelTTF::create("0", "Arial", 45);
bestScoreValTxt->setPositionX(scoreValTxt->getPositionX());
bestScoreValTxt->setPositionY(bestScoreTxt->getPositionY());
bestScoreValTxt->setTag(bestScoreValTxtTag);
this->addChild(bestScoreValTxt);
LabelTTF* replayTxt = LabelTTF::create("Replay", "Arial", 45);
MenuItemLabel* replayBtn = MenuItemLabel::create(replayTxt);
replayBtn->setTag(replayBtnTag);
LabelTTF* shareTxt = LabelTTF::create("Share", "Arial", 45);
MenuItemLabel* shareBtn = MenuItemLabel::create(shareTxt);
Menu* menu = Menu::create(replayBtn, shareBtn, NULL);
menu->setPositionX(ScreenUtil::getCenter().x);
menu->setPositionY(ScreenUtil::getCenter().y - 70);
menu->alignItemsHorizontallyWithPadding(50);
menu->setTag(menuTag);
this->addChild(menu);
}
示例9: CC_CALLBACK_1
bool MapEditer::init()
{
if (!Layer::init())
return false;
m_layer = Layer::create();
this->addChild(m_layer, 1);
Sprite* background = Sprite::create(FileStuff::BACKGROUND_BOTTOM);
float scale = (Director::getInstance()->getVisibleSize().width) / (background->getContentSize().width);
background->setAnchorPoint(Point::ZERO);
background->setScale(scale);
this->addChild(background);
Sling* sling = Sling::create();
this->addChild(sling);
EventListenerMouse* mouseListener = EventListenerMouse::create();
mouseListener->onMouseDown = CC_CALLBACK_1(MapEditer::onMouseDown, this);
mouseListener->onMouseScroll = CC_CALLBACK_1(MapEditer::OnMouseScroll, this);
m_clicked_sprite = nullptr;
_eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
EventListenerKeyboard* keyboardListener = EventListenerKeyboard::create();
keyboardListener->onKeyPressed = CC_CALLBACK_1(MapEditer::OnKeyPressed, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyboardListener, this);
m_pressedKey = static_cast<EventKeyboard::KeyCode>(-1);
MenuItemLabel* saveButton = MenuItemLabel::create(Label::create("Save", FileStuff::FONT_ARIAL, 20));
saveButton->setPosition(170, 10);
saveButton->setName("saveButton");
this->addChild(saveButton);
MenuItemLabel* playButton = MenuItemLabel::create(Label::create("Play", FileStuff::FONT_ARIAL, 20));
playButton->setPosition(220, 10);
playButton->setName("playButton");
this->addChild(playButton);
MenuItemLabel* backButton = MenuItemLabel::create(Label::create("Back", FileStuff::FONT_ARIAL, 20));
backButton->setPosition(270, 10);
backButton->setName("backButton");
this->addChild(backButton);
MenuItemLabel* warning = MenuItemLabel::create(Label::create("If complete making level\nCHANGE FILE NAME", FileStuff::FONT_ARIAL, 15));
warning->setPosition(200, 40);
warning->setName("warning");
this->addChild(warning);
vector<TargetInfo> infoList;
string fileName = FileStuff::EDITING_FILENAME;
//load from file
if (!cppson::loadFile(infoList, fileName))
{
CCLOG("Target Load Fail.");
return true;
}
else
{
for (TargetInfo targetInfo : infoList)
{
Sprite* sprite = nullptr;
Point point;
switch (targetInfo.m_name.get())
{
case TargetInfo::BUBBLE:
sprite = Sprite::create(FileStuff::BUBBLE);
break;
case TargetInfo::ENEMY:
sprite = Sprite::create(FileStuff::ENEMY);
break;
case TargetInfo::MIRROR:
sprite = Sprite::create(FileStuff::MIRROR);
break;
case TargetInfo::VIRTICAL_MIRROR:
sprite = Sprite::create(FileStuff::VIRTICAL_MIRROR);
break;
case TargetInfo::STAR:
sprite = Sprite::create(FileStuff::BRICK);
break;
default:
sprite = Sprite::create(FileStuff::ENEMY); //default sprite
}
sprite->setTag(targetInfo.m_name.get());
point = Point(targetInfo.m_position.get().x.get(), targetInfo.m_position.get().y.get());
sprite->setPosition(point);
sprite->setRotation(targetInfo.m_rotation.get());
sprite->setScaleX(targetInfo.m_scale.get().x.get());
sprite->setScaleY(targetInfo.m_scale.get().y.get());
if (sprite)
{
m_layer->addChild(sprite);
}
//.........这里部分代码省略.........
示例10: _sioClient
SocketIOTestLayer::SocketIOTestLayer(void)
: _sioClient(NULL)
, _sioEndpoint(NULL)
{
//set the clients to NULL until we are ready to connect
Size winSize = Director::getInstance()->getWinSize();
const int MARGIN = 40;
const int SPACE = 35;
LabelTTF *label = LabelTTF::create("SocketIO Extension Test", "Arial", 28);
label->setPosition(Point(winSize.width / 2, winSize.height - MARGIN));
addChild(label, 0);
Menu *menuRequest = Menu::create();
menuRequest->setPosition(Point::ZERO);
addChild(menuRequest);
// Test to create basic client in the default namespace
LabelTTF *labelSIOClient = LabelTTF::create("Open SocketIO Client", "Arial", 22);
MenuItemLabel *itemSIOClient = MenuItemLabel::create(labelSIOClient, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOClientClicked, this));
itemSIOClient->setPosition(Point(VisibleRect::left().x + labelSIOClient->getContentSize().width / 2 + 5, winSize.height - MARGIN - SPACE));
menuRequest->addChild(itemSIOClient);
// Test to create a client at the endpoint '/testpoint'
LabelTTF *labelSIOEndpoint = LabelTTF::create("Open SocketIO Endpoint", "Arial", 22);
MenuItemLabel *itemSIOEndpoint = MenuItemLabel::create(labelSIOEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOEndpointClicked, this));
itemSIOEndpoint->setPosition(Point(VisibleRect::right().x - labelSIOEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - SPACE));
menuRequest->addChild(itemSIOEndpoint);
// Test sending message to default namespace
LabelTTF *labelTestMessage = LabelTTF::create("Send Test Message", "Arial", 22);
MenuItemLabel *itemTestMessage = MenuItemLabel::create(labelTestMessage, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageClicked, this));
itemTestMessage->setPosition(Point(VisibleRect::left().x + labelTestMessage->getContentSize().width / 2 + 5, winSize.height - MARGIN - 2 * SPACE));
menuRequest->addChild(itemTestMessage);
// Test sending message to the endpoint '/testpoint'
LabelTTF *labelTestMessageEndpoint = LabelTTF::create("Test Endpoint Message", "Arial", 22);
MenuItemLabel *itemTestMessageEndpoint = MenuItemLabel::create(labelTestMessageEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageEndpointClicked, this));
itemTestMessageEndpoint->setPosition(Point(VisibleRect::right().x - labelTestMessageEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 2 * SPACE));
menuRequest->addChild(itemTestMessageEndpoint);
// Test sending event 'echotest' to default namespace
LabelTTF *labelTestEvent = LabelTTF::create("Send Test Event", "Arial", 22);
MenuItemLabel *itemTestEvent = MenuItemLabel::create(labelTestEvent, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventClicked, this));
itemTestEvent->setPosition(Point(VisibleRect::left().x + labelTestEvent->getContentSize().width / 2 + 5, winSize.height - MARGIN - 3 * SPACE));
menuRequest->addChild(itemTestEvent);
// Test sending event 'echotest' to the endpoint '/testpoint'
LabelTTF *labelTestEventEndpoint = LabelTTF::create("Test Endpoint Event", "Arial", 22);
MenuItemLabel *itemTestEventEndpoint = MenuItemLabel::create(labelTestEventEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventEndpointClicked, this));
itemTestEventEndpoint->setPosition(Point(VisibleRect::right().x - labelTestEventEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 3 * SPACE));
menuRequest->addChild(itemTestEventEndpoint);
// Test disconnecting basic client
LabelTTF *labelTestClientDisconnect = LabelTTF::create("Disconnect Socket", "Arial", 22);
MenuItemLabel *itemClientDisconnect = MenuItemLabel::create(labelTestClientDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestClientDisconnectClicked, this));
itemClientDisconnect->setPosition(Point(VisibleRect::left().x + labelTestClientDisconnect->getContentSize().width / 2 + 5, winSize.height - MARGIN - 4 * SPACE));
menuRequest->addChild(itemClientDisconnect);
// Test disconnecting the endpoint '/testpoint'
LabelTTF *labelTestEndpointDisconnect = LabelTTF::create("Disconnect Endpoint", "Arial", 22);
MenuItemLabel *itemTestEndpointDisconnect = MenuItemLabel::create(labelTestEndpointDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEndpointDisconnectClicked, this));
itemTestEndpointDisconnect->setPosition(Point(VisibleRect::right().x - labelTestEndpointDisconnect->getContentSize().width / 2 - 5, winSize.height - MARGIN - 4 * SPACE));
menuRequest->addChild(itemTestEndpointDisconnect);
// Sahred Status Label
_sioClientStatus = LabelTTF::create("Not connected...", "Arial", 14, Size(320, 100), Label::HAlignment::LEFT);
_sioClientStatus->setAnchorPoint(Point(0, 0));
_sioClientStatus->setPosition(Point(VisibleRect::left().x, VisibleRect::rightBottom().y));
this->addChild(_sioClientStatus);
// Back Menu
MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(SocketIOTestLayer::toExtensionsMainLayer, this));
itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
Menu *menuBack = Menu::create(itemBack, NULL);
menuBack->setPosition(Point::ZERO);
addChild(menuBack);
}
示例11: Point
// on "init" you need to initialize your instance
bool TestSocial::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
MySocialManager::getInstance()->loadPlugins();
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
Point posMid = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
Point posBR = Point(origin.x + visibleSize.width, origin.y);
MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestSocial::menuBackCallback, this));
Size backSize = pBackItem->getContentSize();
pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2));
// create menu, it's an autorelease object
Menu* pMenu = Menu::create(pBackItem, NULL);
pMenu->setPosition( Point::ZERO );
LabelTTF* label1 = LabelTTF::create("Submit Score", "Arial", 28);
MenuItemLabel* pItemSubmit = MenuItemLabel::create(label1, CC_CALLBACK_1(TestSocial::testSubmit, this));
pItemSubmit->setAnchorPoint(Point(0.5f, 0));
pMenu->addChild(pItemSubmit, 0);
pItemSubmit->setPosition(posMid + Point(-140, -60));
LabelTTF* label2 = LabelTTF::create("Unlock Achievement", "Arial", 28);
MenuItemLabel* pItemUnlock = MenuItemLabel::create(label2, CC_CALLBACK_1(TestSocial::testUnlock, this));
pItemUnlock->setAnchorPoint(Point(0.5f, 0));
pMenu->addChild(pItemUnlock, 0);
pItemUnlock->setPosition(posMid + Point(140, -60));
LabelTTF* label3 = LabelTTF::create("Show Leaderboard", "Arial", 28);
MenuItemLabel* pItemLeader = MenuItemLabel::create(label3, CC_CALLBACK_1(TestSocial::testLeaderboard, this));
pItemLeader->setAnchorPoint(Point(0.5f, 0));
pMenu->addChild(pItemLeader, 0);
pItemLeader->setPosition(posMid + Point(-140, -120));
LabelTTF* label4 = LabelTTF::create("Show Achievement", "Arial", 28);
MenuItemLabel* pItemAchi = MenuItemLabel::create(label4, CC_CALLBACK_1(TestSocial::testAchievement, this));
pItemAchi->setAnchorPoint(Point(0.5f, 0));
pMenu->addChild(pItemAchi, 0);
pItemAchi->setPosition(posMid + Point(140, -120));
// create optional menu
// cases item
_caseItem = MenuItemToggle::createWithCallback(NULL,
MenuItemFont::create( s_aTestCases[0].c_str() ),
NULL );
int caseLen = sizeof(s_aTestCases) / sizeof(std::string);
for (int i = 1; i < caseLen; ++i)
{
_caseItem->getSubItems().pushBack( MenuItemFont::create( s_aTestCases[i].c_str() ) );
}
_caseItem->setPosition(posMid + Point(0, 120));
pMenu->addChild(_caseItem);
this->addChild(pMenu, 1);
return true;
}
示例12: cccontrol_selector
void StartScene::toSetting(){
auto director = Director::getInstance();
RenderTexture* renderTexture = RenderTexture::create(visibleSize.width, visibleSize.height);
renderTexture->begin();
this->getParent()->visit();
renderTexture->end();
auto scene = pausePopup::createScene(renderTexture, "images/popupBg1.png");
auto layer = pausePopup::create(renderTexture, "images/popupBg1.png");
scene->addChild(layer, 1);
layer->contentText = Label::createWithTTF("游戏设置", "fonts/msyhbd.ttc", 20);
layer->contentText->setPosition(layer->menuSprite->getContentSize().width / 2, layer->menuSprite->getContentSize().height / 5 * 4);
layer->menuSprite->addChild(layer->contentText);
auto musicSetting = Label::createWithTTF("音量设置", "fonts/msyhbd.ttc", 15);
musicSetting->setPosition(layer->menuSprite->getContentSize().width / 3, layer->menuSprite->getContentSize().height / 5 * 3);
layer->menuSprite->addChild(musicSetting);
slider = ControlSlider::create("images/slider/slider1.png","images/slider/slider0.png","images/slider/slider2.png");
slider->setPosition(layer->menuSprite->getContentSize().width / 3*2, layer->menuSprite->getContentSize().height / 5 * 3);
slider->setMinimumValue(0.0f);
slider->setMaximumValue(100.0f);
auto initValue = 50.0f;
if (database->getBoolForKey("isExit")) initValue = database->getFloatForKey("music");
slider->setValue(initValue);
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(StartScene::musicSlider), Control::EventType::VALUE_CHANGED);
layer->menuSprite->addChild(slider);
auto resetLabel = Label::createWithTTF("重置游戏", "fonts/msyhbd.ttc", 15);
MenuItemLabel* resetItem = MenuItemLabel::create(resetLabel, CC_CALLBACK_0(StartScene::resetGame,this));
resetItem->setPosition(0, 0);
auto resetMenu = Menu::create(resetItem,NULL);
resetMenu->setPosition(layer->menuSprite->getContentSize().width / 3, layer->menuSprite->getContentSize().height / 5 * 2);
layer->menuSprite->addChild(resetMenu);
auto backLabel = Label::createWithTTF("返回游戏", "fonts/msyhbd.ttc", 15);
backLabel->setColor(Color3B::BLACK);
auto backItem = MenuItemLabel::create(backLabel, CC_CALLBACK_0(pausePopup::backToGame, layer));
backItem->setPosition(backItem->getContentSize().width * 3 / 2, 0);
layer->menu = Menu::create(backItem, NULL);
layer->menu->setPosition(layer->menuSprite->getContentSize().width / 2, layer->menuSprite->getContentSize().height / 12);
layer->menuSprite->addChild(layer->menu, 10);
//auto popupScene = Popup::createScene(renderTexture,"images/popupBg.png");
//auto popup = Popup::create("images/popupBg.png");
//this->addChild(popup, 10);
//Action* popupAction = Sequence::create(ScaleTo::create(0.0f, 0.0f),
// ScaleTo::create(0.06f, 1.05f),
// ScaleTo::create(0.08f, 0.95f),
// ScaleTo::create(0.08f, 1.0f), NULL);
//popup->runAction(popupAction);
//Director::getInstance()->pause();
director->pushScene(scene);
//Director::getInstance()->replaceScene(popupScene);
}
示例13: setTouchEnabled
// on "init" you need to initialize your instance
bool Game::init() {
if ( !LayerColor::init()) {//initWithColor(Color4B(255, 0, 0, 255)) ) {
return false;
}
// add background music
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("action.mp3", true);
// enable touch events
setTouchEnabled(true);
// get screen size
Size screenSize = Director::getInstance()->getVisibleSize();
// add menu button
MenuItemLabel* menuItem = MainMenu::createButton("End Game", CC_CALLBACK_1(Game::menuCallback, this));
menuItem->setPosition(Point(screenSize.width - menuItem->getContentSize().width/2 - Letter::PADDING,
menuItem->getContentSize().height/2 + Letter::PADDING));
// create menu, it's an autorelease object
auto menu = Menu::create(menuItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu, 1);
// display score on the screen
scoreLabel = LabelTTF::create("Score: 0", "Arial", 35);
scoreLabel->setColor(Color3B(255, 255, 255));
scoreLabel->setPosition(Point(Letter::PADDING + scoreLabel->getContentSize().width/2, screenSize.height-scoreLabel->getContentSize().height/2 - Letter::PADDING));
this->addChild(scoreLabel, 1);
// display moves on the screen
movesLabel = LabelTTF::create("Moves: 20", "Arial", 35);
movesLabel->setColor(Color3B(255, 255, 255));
movesLabel->setPosition(Point(screenSize.width - movesLabel->getContentSize().width/2 - Letter::PADDING, screenSize.height - movesLabel->getContentSize().height/2 - Letter::PADDING));
this->addChild(movesLabel, 1);
// set number of moves
moves = STARTING_MOVES;
// create board
Board board = Board(this);
// whether a letter has been selected
bool letterSelected = false;
auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE);
listener->setSwallowTouches(false);
listener->onTouchBegan = [=](Touch* touch, Event* event) mutable {
//log("touch began");
Point location = touch->getLocation();//->getLocationInView();
// TODO: Detect touches on labels
for (int i = 0; i < Board::BOARD_SIZE; i++) {
vector<Letter> row = board.letters[i];
for (int j = 0; j < Board::BOARD_SIZE; j++) {
Letter l = row[j];
if (location.getDistance(l.posn) < 30) {
//log("touched %c", l.letter);
l.label->setColor(cocos2d::Color3B(0, 255, 0));
//cocos2d::log("letter selected %s, %c", letterSelected ? "true" : "false", board.selected.letter);
if (!letterSelected) {
// first letter selected
board.selected = l;
letterSelected = true;
//cocos2d::log("set selected to %c, %s", board.selected.letter, letterSelected ? "true" : "false");
} else if (board.selected != l) {
// second selected letter is not the same as first
board.letterSwap(l);
letterSelected = false;
UpdateScore();
UpdateMoves();
} else {
// same letter was selected
//cocos2d::log("you selected the same letter %c", board.selected.letter);
// set letterSelected to false
letterSelected = false;
// reset selected color
board.selected.label->setColor(cocos2d::Color3B(255, 255, 255));
// set selected letter to empty Letter
board.selected = Letter();
}
return true;
}
}
}
return false;
};
// unused listeners
//listener->onTouchMoved = [](Touch* touch, Event* event) { log("touch moved"); };
//listener->onTouchEnded = [](Touch* touch, Event* event) { log("touch ended"); };
//listener->onTouchCancelled = [](Touch* touch, Event* event) { log("touch canceled"); };
// The priority of the touch listener is based on the draw order of sprite
//EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, sprite);
// Or the priority of the touch listener is a fixed value
EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 100);
return true;
//.........这里部分代码省略.........
示例14: CC_CALLBACK_1
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
closeItem->setPosition( Point(closeItem->getContentSize().width / 2 , 50) );
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
auto label = LabelTTF::create("Hello World", "Arial", 24);
// position the label on the center of the screen
label->setPosition(Point(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png");
// position the sprite on the center of the screen
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
float step = 35;
float yPos = 0;
for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
char buf[64];
sprintf(buf, s_EventMenuItem[i].id.c_str(), ++_indexes[i]);
auto label = LabelTTF::create(buf, "Arial", 24);
MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(HelloWorld::menuEventCallback, this));
menu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);
yPos = visibleSize.height - step*i - 100;
pMenuItem->setPosition( Point(visibleSize.width / 2, yPos));
}
// add next menu
MenuItemImage *pNextItem = MenuItemImage::create("f1.png","f1.png",CC_CALLBACK_1(HelloWorld::menuNextCallback,this));
pNextItem->setPosition( Point(visibleSize.width - pNextItem->getContentSize().width / 2, 50) );
// create menu, it's an autorelease object
Menu* pNextMenu = Menu::create(pNextItem, NULL);
pNextMenu->setPosition( Point::ZERO );
this->addChild(pNextMenu, 1);
return true;
}
示例15: MyAdsListener
// on "init" you need to initialize your instance
bool TestAds::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
_listener = new MyAdsListener();
_admob = dynamic_cast<ProtocolAds*>(PluginManager::getInstance()->loadPlugin("AdsAdmob"));
_flurryAds = dynamic_cast<ProtocolAds*>(PluginManager::getInstance()->loadPlugin("AdsFlurry"));
TAdsDeveloperInfo devInfo;
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
devInfo["AdmobID"] = ADMOB_ID_IOS;
devInfo["FlurryAppKey"] = FLURRY_KEY_IOS;
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
devInfo["AdmobID"] = ADMOB_ID_ANDROID;
devInfo["FlurryAppKey"] = FLURRY_KEY_ANDROID;
#endif
_admob->configDeveloperInfo(devInfo);
_admob->setAdsListener(_listener);
_admob->setDebugMode(true);
_flurryAds->configDeveloperInfo(devInfo);
_flurryAds->setAdsListener(_listener);
_flurryAds->setDebugMode(true);
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
Point posMid = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
Point posBR = Point(origin.x + visibleSize.width, origin.y);
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestAds::menuBackCallback, this));
Size backSize = pBackItem->getContentSize();
pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2));
// create menu, it's an autorelease object
Menu* pMenu = Menu::create(pBackItem, NULL);
pMenu->setPosition( Point::ZERO );
LabelTTF* label1 = LabelTTF::create("ShowAds", "Arial", 24);
MenuItemLabel* pItemShow = MenuItemLabel::create(label1, CC_CALLBACK_1(TestAds::testShow, this));
pItemShow->setAnchorPoint(Point(0.5f, 0));
pMenu->addChild(pItemShow, 0);
pItemShow->setPosition(posMid + Point(-100, -120));
LabelTTF* label2 = LabelTTF::create("HideAds", "Arial", 24);
MenuItemLabel* pItemHide = MenuItemLabel::create(label2, CC_CALLBACK_1(TestAds::testHide, this));
pItemHide->setAnchorPoint(Point(0.5f, 0));
pMenu->addChild(pItemHide, 0);
pItemHide->setPosition(posMid + Point(100, -120));
// create optional menu
// cases item
_caseItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TestAds::caseChanged, this),
MenuItemFont::create( s_aTestCases[0].c_str() ),
NULL );
int caseLen = sizeof(s_aTestCases) / sizeof(std::string);
for (int i = 1; i < caseLen; ++i)
{
_caseItem->getSubItems()->addObject( MenuItemFont::create( s_aTestCases[i].c_str() ) );
}
_caseItem->setPosition(posMid + Point(-200, 120));
pMenu->addChild(_caseItem);
// poses item
_posItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TestAds::posChanged, this),
MenuItemFont::create( s_aTestPoses[0].c_str() ),
NULL );
int posLen = sizeof(s_aTestPoses) / sizeof(std::string);
for (int i = 1; i < posLen; ++i)
{
_posItem->getSubItems()->addObject( MenuItemFont::create( s_aTestPoses[i].c_str() ) );
}
_posItem->setPosition(posMid + Point(200, 120));
pMenu->addChild(_posItem);
// init options
_ads = _admob;
_pos = ProtocolAds::kPosCenter;
// init the AdsInfo
adInfo["AdmobType"] = "1";
adInfo["AdmobSizeEnum"] = "1";
adInfo["FlurryAdsID"] = "BANNER_MAIN_VC";
adInfo["FlurryAdsSize"] = "2";
this->addChild(pMenu, 1);
return true;
}