本文整理汇总了C++中CC_CALLBACK_1函数的典型用法代码示例。如果您正苦于以下问题:C++ CC_CALLBACK_1函数的具体用法?C++ CC_CALLBACK_1怎么用?C++ CC_CALLBACK_1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CC_CALLBACK_1函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CC_CALLBACK_2
// on "init" you need to initialize your instance
bool MainScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto keyboardListener = EventListenerKeyboard::create();
keyboardListener->onKeyPressed = CC_CALLBACK_2(MainScene::keyPressed, this);
keyboardListener->onKeyReleased = CC_CALLBACK_2(MainScene::keyReleased, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(keyboardListener, this);
/////////////////////////////
// 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(MainScene::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::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(Vec2(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(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
//this->addChild(sprite, 0);
auto minSize = ::std::min(visibleSize.width, visibleSize.height);
auto fieldSize = minSize * 0.8;
auto layerColorBG = LayerColor::create(Color4B(200, 190, 180, 255), fieldSize, fieldSize);
layerColorBG->setPosition(Vec2(origin.x + visibleSize.width/2 - fieldSize/2,
origin.y + visibleSize.height/2 - fieldSize/2));
this->addChild(layerColorBG);
auto size = board_.size();
cells_.assign(size, ::std::vector<UiCell>(size, UiCell()));
const auto cellsProportion = 0.90;
auto cellSize = fieldSize * cellsProportion / size;
auto cellMargin = fieldSize * (1 - cellsProportion) / (size + 1);
for (auto i = 0; i < size; ++i) {
for (auto j = 0; j < size; ++j) {
auto cellPos = Vec2(cellMargin + j * (cellSize + cellMargin),
fieldSize - cellMargin - cellSize - i * (cellSize + cellMargin));
auto layerCell = LayerColor::create(Color4B(180, 190, 200, 255), cellSize, cellSize);
layerCell->setPosition(cellPos);
layerColorBG->addChild(layerCell);
layerCell = LayerColor::create(Color4B(190, 200, 180, 0), cellSize, cellSize);
layerCell->setPosition(cellPos);
layerColorBG->addChild(layerCell);
auto label = LabelTTF::create("", "Arial", 48);
label->setPosition(Vec2(cellSize/2, cellSize/2));
layerCell->addChild(label);
cells_[i][j] = { layerCell, label };
}
}
board_.spawnNew();
board_.spawnNew();
return true;
//.........这里部分代码省略.........
示例2: Size
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
// TiledMapEditorで生成したマップを表示する
_map = TMXTiledMap::create("TMX/stage1.tmx");
_mapLayer = _map->getLayer("layer1");
// マップのサイズ
Size mapSize = Size(_map->getTileSize().width * _map->getMapSize().width,
_map->getTileSize().height * _map->getMapSize().height);
// スクロールビュー
ScrollView *scrollView = ScrollView::create(mapSize*3);
scrollView->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
scrollView->setPosition(Vec2(100, 100));
scrollView->setMaxScale(5.0f);
scrollView->setBounceable(false);
scrollView->setContentSize(mapSize*3);
this->addChild(scrollView);
// 中のレイヤー
Layer *innerLayer = Layer::create();
scrollView->addChild(innerLayer);
// スクロールビューの背景
Sprite *sprite = Sprite::create();
sprite->setTextureRect(Rect(0, 0, scrollView->getContentSize().width, scrollView->getContentSize().height));
sprite->setColor(Color3B(230,230,230));
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
innerLayer->addChild(sprite);
// マップを表示
_map->setScale(3);
innerLayer->addChild(_map);
// キャラクターを表示
_character = Sprite::create("TMX/character.png");
_character->setAnchorPoint(Vec2(0.5f, 0.25f));
_charaPos = Vec2(0, 0);
_character->setPosition(_mapLayer->getPositionAt(_charaPos) + _map->getTileSize()/2);
_map->addChild(_character);
// サイコロボタン
_isMoving = false;
MenuItemLabel *dice = MenuItemLabel::create(Label::createWithSystemFont("サイコロ", "arial", 30.0f),
CC_CALLBACK_1(HelloWorld::dice, this));
dice->setPosition(Vec2(600, 0));
this->addChild(Menu::create(dice, NULL));
// サイコロの目
Label *pips = Label::createWithSystemFont("-", "arial", 30.0f);
pips->setPosition(Vec2(1200, 300));
pips->setTag(10);
this->addChild(pips);
return true;
}
示例3: CC_CALLBACK_2
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
/////////////////////////////
// 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(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::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(Vec2(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);
player = Player::create();
player->setPosition(Vec2(origin.x + visibleSize.width / 2
, origin.y + visibleSize.height / 2));
this->addChild(player, 5);
this->scheduleUpdate();
return true;
}
示例4: CC_CALLBACK_1
// on "init" you need to initialize your instance
bool Practice1::init()
{
//////////////////////////////
// 1. super init first
if (!Layer::init())
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 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(Practice1::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
origin.y + closeItem->getContentSize().height / 2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
/////////////////////////////
// 3. add your codes below...
auto label = Label::createWithTTF("練習シーン1", "fonts/07やさしさゴシック.ttf", 24);
label->setAnchorPoint(Vec2(0.0f, 0.0f));
label->setPosition(origin.x, origin.y + visibleSize.height);
this->addChild(label);
nowCount = Label::createWithTTF("現在のカウント: 0", "fonts/07やさしさゴシック.ttf", 24);
nowCount->setPosition(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2);
this->addChild(nowCount);
count = 0;
// add this scene to update schedule
//this->scheduleUpdate();
//this->schedule(schedule_selector(Practice1::updateByTimer), 1.0f);
// create field
// 空のスプライトを用意
float fieldWidth = visibleSize.width / 2;
float fieldHeight = visibleSize.height + 100.0f;
float fieldBlockWidth = fieldWidth / 8;
const int fieldObjectNumber = 3;
Rect fieldSizes[fieldObjectNumber] = {
{ 0, 0, fieldBlockWidth, fieldHeight },
{ 0, 0, fieldWidth, fieldBlockWidth },
{ 0, 0, fieldBlockWidth, fieldHeight },
};
Point fieldPoints[fieldObjectNumber] = {
{ origin.x + visibleSize.width / 2 - fieldWidth/2 - fieldBlockWidth, origin.x + visibleSize.height },
{ origin.x + visibleSize.width / 2 - fieldWidth / 2, origin.x + visibleSize.height },
{ origin.x + visibleSize.width / 2 + fieldWidth / 2, origin.x + visibleSize.height },
};
//for (int i = 0; i < fieldObjectNumber; ++i)
for (int i = 0; i < 1; ++i)
{
Sprite* field = Sprite::create("HelloWorld.png");
//Sprite* field = Sprite::create();
//field->setColor(Color3B::WHITE);
field->setAnchorPoint(Vec2(0, 1.0));
field->setTextureRect(fieldSizes[i]);
field->setPosition(fieldPoints[i]);
//auto fieldPhysics = PhysicsBody::createBox(fieldSizes[i].size);
auto fieldPhysics = PhysicsBody::createBox(Size(field->getContentSize().width, field->getContentSize().height));
fieldPhysics->setDynamic(false);
fieldPhysics->setRotationEnable(false);
field->setPhysicsBody(fieldPhysics);
this->addChild(field);
}
auto sprite2 = Sprite::create("EDGE(after).png");
sprite2->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height/2 + origin.y));
auto sprite2Physics = PhysicsBody::createBox(Size(sprite2->getContentSize().width, sprite2->getContentSize().height));
sprite2Physics->setDynamic(true);
sprite2Physics->setRotationEnable(false);
sprite2->setPhysicsBody(sprite2Physics);
this->addChild(sprite2);
return true;
}
示例5: CC_CALLBACK_1
void CGameView::onEnter()
{
Layer::onEnter();
//----------------------------------------------------
//FIXME
count = 0;
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(CGameView::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
origin.y + closeItem->getContentSize().height / 2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
//----------------------------------------------------
log("CGameView OnEnter...");
auto lisnter = EventListenerTouchOneByOne::create();
lisnter->onTouchBegan = CC_CALLBACK_2(CGameView::onTouchBegan, this);
lisnter->onTouchEnded = CC_CALLBACK_2(CGameView::onTouchEnded, this);
lisnter->onTouchMoved = CC_CALLBACK_2(CGameView::onTouchMove, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(lisnter, this);
//--------------------------------------------------------------------
m_pPath = new CPath();
m_pDrawNode = DrawNode::create();
m_pSp = CMySprite::create();
m_pPlayer = CGamePlayer::create();
m_pShowArea = CShowArea::create();
m_pGameLogic = CGameLogic::create();
//------------------------------------
m_pSp->setPath(m_pPath);
m_pSp->setPlayer(m_pPlayer);
m_pSp->setShowArea(m_pShowArea);
m_pSp->setVisible(false);
m_pShowArea->setPath(m_pPath);
m_pShowArea->setPosition(origin);
m_pPlayer->m_refSp = m_pSp;
m_pPlayer->setVisible(false);
m_pGameLogic->m_refPath = m_pPath;
m_pGameLogic->m_refPlayer = m_pPlayer;
m_pGameLogic->m_refShowArea = m_pShowArea;
m_pGameLogic->m_refSp = m_pSp;
m_pGameLogic->setAnchorPoint(Vec2::ZERO);
//----------------------------
addChild(m_pShowArea);
addChild(m_pSp);
addChild(m_pDrawNode);
addChild(m_pGameLogic);
addChild(m_pPlayer);
//------------------------------------
m_oAllRander.push_back(m_pSp);
m_oAllRander.push_back(m_pShowArea);
m_oAllRander.push_back(m_pPath);
m_oAllRander.push_back(m_pPlayer);
//----------------------------------------
m_oAllRunner.push_back(m_pSp);
m_oAllRunner.push_back(m_pPlayer);
//------------------------------------------
CEventDispatcher::getInstrance()->regsiterEvent(EVENT_WIN, this);
CEventDispatcher::getInstrance()->regsiterEvent(EVENT_TIMEOUT, this);
CEventDispatcher::getInstrance()->regsiterEvent(EVENT_PLAYERDIE, this);
setState(STATE_INIT);
schedule(schedule_selector(CGameView::run));
}
示例6: new
void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
{
std::srand(0);
_subtestNumber = asubtest;
_subTest = new (std::nothrow) SubTest;
_subTest->initWithSubTest(asubtest, this);
auto s = Director::getInstance()->getWinSize();
_lastRenderedCount = 0;
_quantityNodes = 0;
MenuItemFont::setFontSize(65);
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(SpriteMainScene::onDecrease, this));
decrease->setColor(Color3B(0,200,20));
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(SpriteMainScene::onIncrease, this));
increase->setColor(Color3B(0,200,20));
auto menu = Menu::create(decrease, increase, nullptr);
menu->alignItemsHorizontally();
menu->setPosition(Vec2(s.width/2, s.height-65));
addChild(menu, 1);
auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30);
infoLabel->setColor(Color3B(0,200,20));
infoLabel->setPosition(Vec2(s.width/2, s.height-90));
addChild(infoLabel, 1, kTagInfoLayer);
// add menu
auto menuLayer = new (std::nothrow) SpriteMenuLayer(true, TEST_COUNT, SpriteMainScene::_s_nSpriteCurCase);
addChild(menuLayer, 1, kTagMenuLayer);
menuLayer->release();
/**
* auto test menu
*/
auto menuAutoTest = Menu::create();
menuAutoTest->setPosition( Vec2::ZERO );
MenuItemFont::setFontName("fonts/arial.ttf");
MenuItemFont::setFontSize(24);
MenuItemFont* autoTestItem = nullptr;
if (SpriteMainScene::_s_autoTest)
{
autoTestItem = MenuItemFont::create("Auto Test On",CC_CALLBACK_1(SpriteMainScene::onAutoTest, this));
}
else
{
autoTestItem = MenuItemFont::create("Auto Test Off",CC_CALLBACK_1(SpriteMainScene::onAutoTest, this));
}
autoTestItem->setTag(1);
autoTestItem->setPosition(Vec2( s.width - 90, s.height / 2));
menuAutoTest->addChild(autoTestItem);
addChild( menuAutoTest, 3, kTagAutoTestMenu );
// Sub Tests
MenuItemFont::setFontSize(28);
auto subMenu = Menu::create();
for (int i = 1; i <= 13; ++i)
{
char str[10] = {0};
sprintf(str, "%d ", i);
auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(SpriteMainScene::testNCallback, this));
itemFont->setTag(i);
subMenu->addChild(itemFont, 10);
if( i<= 4)
itemFont->setColor(Color3B(200,20,20));
else if(i <= 8)
itemFont->setColor(Color3B(0,200,20));
else if( i<=12)
itemFont->setColor(Color3B(0,20,200));
else
itemFont->setColor(Color3B::GRAY);
}
subMenu->alignItemsHorizontally();
subMenu->setPosition(Vec2(s.width/2, 80));
addChild(subMenu, 2);
// add title label
auto label = Label::createWithTTF(title(), "fonts/arial.ttf", 32);
addChild(label, 1);
label->setPosition(Vec2(s.width/2, s.height-50));
// subtitle
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/Thonburi.ttf", 16);
addChild(l, 9999);
l->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
}
while(_quantityNodes < nNodes)
onIncrease(this);
}
示例7: CC_CALLBACK_1
bool PhysicListener::init(){
EventListenerPhysicsContact::init();
this->onContactBegin = CC_CALLBACK_1(PhysicListener::onPhysicContactBegin, this);
return true;
};
示例8: init
// on "init" you need to initialize your instance
bool MainMenuScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
bool musicOn = UserDefault::getInstance()->getBoolForKey("MusicOn",true);
if(!CocosDenshion::SimpleAudioEngine::getInstance()->isBackgroundMusicPlaying())
{
CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("audio/Fantasy Armies.mp3");
CocosDenshion::SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(0.5);
CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
if(musicOn)
{
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("audio/Fantasy Armies.mp3",true);
}
}
auto gameTitle = Label::createWithTTF("Koncentric", "fonts/Marker Felt.ttf", 100);
gameTitle->setPosition(Point(visibleSize.width/2+origin.x,visibleSize.height*0.9+origin.y));
gameTitle->setColor(Color3B(100,25, 200));
auto playItem = MenuItemFont::create("Play",CC_CALLBACK_1(MainMenuScene::goToGameScene,this));
playItem->setColor(cocos2d::Color3B::BLUE);
playItem->setScale(2);
playItem->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height*0.6+origin.y));
auto optionItem = MenuItemFont::create("Options",CC_CALLBACK_1(MainMenuScene::goToGameScene,this));
playItem->setTag(0);
optionItem->setColor(cocos2d::Color3B::BLUE);
optionItem->setScale(2);
optionItem->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height*0.6-playItem->getContentSize().height*2+origin.y));
optionItem->setTag(1);
auto bestTimeItem = MenuItemFont::create("Best Times",CC_CALLBACK_1(MainMenuScene::goToGameScene,this));
bestTimeItem->setColor(cocos2d::Color3B::BLUE);
bestTimeItem->setScale(2);
bestTimeItem->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height*0.6-playItem->getContentSize().height*2-optionItem->getContentSize().height*2+origin.y));
bestTimeItem->setTag(2);
ParticleSystemQuad* m_emitter = new ParticleSystemQuad();
m_emitter = ParticleFlower::create();
// m_emitter->setEmitterMode(cocos2d::ParticleSystem::Mode::RADIUS);
m_emitter->setEmissionRate(20);
m_emitter->setSpeed(150);
// m_emitter->setColor(Color3B(50, 100, 200));
m_emitter->setStartColor(Color4F(0, 180, 200, 255));
m_emitter->setPosition(Vec2(visibleSize.width/2+origin.x,visibleSize.height*0.53+origin.y));
// m_emitter->setStartRadius(10);
// m_emitter->setEndRadius(50);
//m_emitter->setGravity(Vec2(0,-90));
// = kCCParticleModeGravity
//m_emitter->modeA.gravity = ccp(0,-90);
auto menu = Menu::create(playItem,optionItem,bestTimeItem,NULL);
menu->setPosition(Point::ZERO);
this->addChild(m_emitter);
this->addChild(gameTitle);
this->addChild(menu);
return true;
}
示例9: CC_CALLBACK_1
// on "init" you need to initialize your instance
bool LeaderBoard::init()
{
//super init first
if (!Layer::init())
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto label = Label::createWithTTF("LEADERBOARD", "fonts/Marker Felt.ttf", 44);
label->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - label->getContentSize().height));
label->setColor(ccc3(255, 215, 0));
this->addChild(label, 1);
auto MainMenu = MenuItemImage::create("Mainmenu.png", "Mainmenu.png", CC_CALLBACK_1(LeaderBoard::GoToMainMenuScene, this));
MainMenu->setPosition(Vec2(visibleSize.width / 2, origin.y + visibleSize.height / 4.5));
auto menu1 = Menu::create(MainMenu, NULL);
menu1->setPosition(Vec2::ZERO);
this->addChild(menu1, 1);
auto label2 = Label::createWithTTF("The Top 10 Scores are:", "fonts/Marker Felt.ttf", 33);
label2->setPosition(Vec2(visibleSize.width / 2, origin.y + visibleSize.height / 1.2));
label2->setColor(ccc3(160, 32, 240));
this->addChild(label2, 1);
auto label3 = Label::createWithTTF("1. ", "fonts/Marker Felt.ttf", 33);
label3->setPosition(Vec2(visibleSize.width / 3, origin.y + visibleSize.height / 1.3));
label3->setColor(ccc3(0, 0, 0));
this->addChild(label3, 1);
auto label4 = Label::createWithTTF("2. ", "fonts/Marker Felt.ttf", 33);
label4->setPosition(Vec2(visibleSize.width / 3, origin.y + visibleSize.height / 1.38));
label4->setColor(ccc3(0, 0, 0));
this->addChild(label4, 1);
auto label5 = Label::createWithTTF("3. ", "fonts/Marker Felt.ttf", 33);
label5->setPosition(Vec2(visibleSize.width / 3, origin.y + visibleSize.height / 1.44));
label5->setColor(ccc3(0, 0, 0));
this->addChild(label5, 1);
auto ExitGame = MenuItemImage::create("Exit.png", "Exit.png",
CC_CALLBACK_1(LeaderBoard::menuCloseCallback, this));
ExitGame->setPosition(Vec2(visibleSize.width / 2, origin.y + visibleSize.height / 6.4));
auto menu = Menu::create(ExitGame, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
//This adds a background to the screen
auto sprite = Sprite::create("Background2.png");
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
return true;
}
示例10: _displayColor
NS_CC_BEGIN
MeshCommand::MeshCommand()
: _displayColor(1.0f, 1.0f, 1.0f, 1.0f)
, _matrixPalette(nullptr)
, _matrixPaletteSize(0)
, _materialID(0)
, _vao(0)
, _material(nullptr)
, _glProgramState(nullptr)
, _stateBlock(nullptr)
, _textureID(0)
{
_type = RenderCommand::Type::MESH_COMMAND;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// listen the event that renderer was recreated on Android/WP8
_rendererRecreatedListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(MeshCommand::listenRendererRecreated, this));
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_rendererRecreatedListener, -1);
#endif
}
示例11: CC_CALLBACK_1
void GameLayer::createTouchManager() {
_touchMgr = TouchManager::create();
_touchMgr->onTouch = CC_CALLBACK_1(GameLayer::onTouch, this);
addChild(_touchMgr);
}
示例12: addShiledLayer
bool StoreSelectLayer::init(int money)
{
if (!Layer::init())
{
return false;
}
addShiledLayer();
willReduceMoney = money;
Sprite * bg_sprite = Sprite::create("Select.png");
bg_sprite->setPosition(Vec2(GET_WINDOWS_SIZE/2));
this->addChild(bg_sprite);
auto trueItem = MenuItemSprite::create(Sprite::create("true.png"), Sprite::create("true.png"),CC_CALLBACK_1(StoreSelectLayer::sendInform,this));
auto falseItem = MenuItemSprite::create(Sprite::create("False.png"),Sprite::create("False.png"),CC_CALLBACK_1(StoreSelectLayer::removeSelfLayer,this));
Menu * selectMenu = Menu::create(trueItem, falseItem,NULL);
selectMenu->alignItemsHorizontallyWithPadding(100);
selectMenu->setPosition(Vec2(bg_sprite->getContentSize().width/2, bg_sprite->getContentSize().height/6));
bg_sprite->addChild(selectMenu);
return true;
}
示例13: Point
// on "init" you need to initialize your instance
bool MainMenuScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto backgroundSprite = Sprite::create( "Background.png" );
backgroundSprite->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y ) );
this->addChild( backgroundSprite );
auto titleSprite = Sprite::create( "Title.png" );
titleSprite->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height - titleSprite->getContentSize( ).height ) );
this->addChild( titleSprite );
auto playItem = MenuItemImage::create( "Play Button.png", "Play Button Clicked.png", CC_CALLBACK_1( MainMenuScene::GoToGameScene, this ) );
playItem->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y ) );
auto menu = Menu::create( playItem, NULL );
menu->setPosition( Point::ZERO );
this->addChild( menu );
return true;
}
示例14: Point
bool rankBirdLayer::init()
{
if (!Layer::init()) {
return false;
}
Size visibleSize=Director::getInstance()->getVisibleSize();
Point origin=Director::getInstance()->getVisibleOrigin();
Sprite *backGround=Sprite::create("night.png");
backGround->setAnchorPoint(Point(0,0));
backGround->setPosition(Point(origin.x,origin.y+visibleSize.height-backGround->getContentSize().height));
this->addChild(backGround,0);
Sprite *floor=Sprite::create("floor.png");
floor->setAnchorPoint(Point(0,0));
floor->setPosition(0,0);
this->addChild(floor);
floor->runAction(RepeatForever::create(Sequence::create(MoveTo::create(0.5, Point(-120,0)),MoveTo::create(0,Point(0,0)), NULL)));
Sprite *rank=Sprite::create("rankBackground.png");
rank->setPosition(270,530);
this->addChild(rank);
Sprite *title=Sprite::create("rankBird.png");
title->setPosition(270,850);
this->addChild(title,1);
load();
MenuItemImage *menuItem=MenuItemImage::create("menu.png", "menu_off.png", CC_CALLBACK_1(rankBirdLayer::menuCallBack0, this));
menuItem->setPosition(80,50);
MenuItemImage *nextItem=MenuItemImage::create("next.png", "next_off.png", CC_CALLBACK_1(rankBirdLayer::menuCallBack1, this));
nextItem->setPosition(460,50);
Menu *menu=Menu::create(menuItem,nextItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu,10);
//排行的显示
int *tempBird= new int[5];
for (int i=0; i<5; i++)
{
std::string score;
std::string number=StringUtils::format("%d",(i+1)); //创建string
tempBird[i]=atoi(scoreBird[i].c_str());// atoi(const char *) 转换为int; .c_str()将std::string转换为char *
if (tempBird[i]==0)
{
score="-";
}
else
{
score=scoreBird[i];
}
labels=Label::createWithTTF(number, "FZKATJW.ttf", 60,Size::ZERO,TextHAlignment::LEFT,TextVAlignment::TOP);
rank->addChild(labels,2);
labels->setPosition(Point(90,280-(50*i)));
labels->enableOutline(Color4B(187,187,187,255),2);
labels=Label::createWithTTF(score, "FZKATJW.ttf", 60,Size::ZERO,TextHAlignment::LEFT,TextVAlignment::TOP);
rank->addChild(labels,2);
labels->setPosition(Point(315,280-(50*i)));
labels->enableOutline(Color4B(187,187,187,255),2);
}
return true;
}
示例15: CC_CALLBACK_2
bool MainMenuLayer::init()
{
if ( !Layer::init() )
{
return false;
}
Size winSize = Director::getInstance()->getWinSize();
// bind touch event
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(MainMenuLayer::onTouchBegan, this);
touchListener->onTouchMoved = CC_CALLBACK_2(MainMenuLayer::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(MainMenuLayer::onTouchEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
// add scene
auto rootNode = CSLoader::createNode("MainMenuScene.csb");
m_pAnimate = CSLoader::createTimeline("MainMenuScene.csb");
rootNode->runAction(m_pAnimate);
m_pAnimate->pause();
this->addChild(rootNode, ZORDER_MAINMENULAYER_MAINLAYER);
// get node
auto nodePlayer = dynamic_cast<Node*>(rootNode->getChildByName("FileNode_Player"));
m_pPlayerAnimate = CSLoader::createTimeline("MainMenuPlayer.csb");
nodePlayer->runAction(m_pPlayerAnimate);
m_pPlayerAnimate->pause();
auto nodeUp = dynamic_cast<Node*>(rootNode->getChildByName("Node_Up"));
auto nodeDown = dynamic_cast<Node*>(rootNode->getChildByName("Node_Down"));
// get text
auto textGameTitle = dynamic_cast<Text*>(nodeUp->getChildByName("Text_GameTitle"));
auto textPlay = dynamic_cast<Text*>(rootNode->getChildByName("Text_Play"));
auto textHighscore = dynamic_cast<Text*>(nodeUp->getChildByName("Text_Highscore"));
auto textGoldNumber = dynamic_cast<Text*>(nodeUp->getChildByName("Node_GoldNumber")->getChildByName("Text_GoldNumber"));
// get button
auto buttonSetting = dynamic_cast<Button*>(nodeUp->getChildByName("Button_Setting"));
buttonSetting->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_Setting, this));
auto buttonSignIn = dynamic_cast<Button*>(nodeDown->getChildByName("Button_SignIn"));
buttonSignIn->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_SignIn, this));
auto buttonAchievement = dynamic_cast<Button*>(nodeDown->getChildByName("Button_Achievement"));
buttonAchievement->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_Achievement, this));
auto buttonLeaderboard = dynamic_cast<Button*>(nodeDown->getChildByName("Button_Leaderboard"));
buttonLeaderboard->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_Leaderboard, this));
auto buttonPurchaseNoAd = dynamic_cast<Button*>(nodeDown->getChildByName("Button_Purchase_noAd"));
buttonPurchaseNoAd->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_PurchaseNoAd, this));
auto buttonUpgrade = dynamic_cast<Button*>(rootNode->getChildByName("Button_Upgrade"));
buttonUpgrade->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_Upgrade, this));
auto buttonReload = dynamic_cast<Button*>(rootNode->getChildByName("Button_Reload"));
buttonReload->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_Reload, this));
auto buttonPurchase = dynamic_cast<Button*>(rootNode->getChildByName("Button_TestPurchase"));
buttonPurchase->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_Purchase, this));
auto buttonReset = dynamic_cast<Button*>(rootNode->getChildByName("Button_ResetGameCenter"));
buttonReset->addClickEventListener(CC_CALLBACK_1(MainMenuLayer::menuCallback_Reset, this));
// set button
#if DEBUG_FLAG == 0
buttonReload->setVisible(false);
buttonPurchase->setVisible(false);
buttonReset->setVisible(false);
#endif
if (CSCClass::CSC_IOSHelper::GameCenter_isAuthenticated()) {
buttonAchievement->setPositionY(10);
buttonLeaderboard->setPositionY(10);
buttonSignIn->setPositionY(-200);
}
else {
buttonAchievement->setPositionY(-200);
buttonLeaderboard->setPositionY(-200);
buttonSignIn->setPositionY(10);
auto listener = EventListenerCustom::create(EVENT_GAMECENTER_AUTHENTICATED, [=](EventCustom* event) {
// change game center buttons when authenticated
buttonAchievement->runAction(MoveTo::create(0.5f, cocos2d::Point(buttonAchievement->getPositionX(), 10)));
buttonLeaderboard->runAction(MoveTo::create(0.5f, cocos2d::Point(buttonLeaderboard->getPositionX(), 10)));
buttonSignIn->runAction(MoveTo::create(0.5f, cocos2d::Point(buttonSignIn->getPositionX(), -200)));
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
if (!m_pGameMediator->getIsAd()) {
buttonPurchaseNoAd->setPositionY(-200);
}
else {
#if IAPTEST_FLAG == 1
CSCClass::CSC_IOSHelper::IAP_requestAllPurchasedProducts(true);
#else
CSCClass::CSC_IOSHelper::IAP_requestAllPurchasedProducts(false);
#endif
auto listener = EventListenerCustom::create(EVENT_RESTORED + "com.reallycsc.endlesslove.adremove", [=](EventCustom* event) {
m_pGameMediator->setIsAd(false);
m_pGameMediator->setIsGuidelineForever(true);
buttonPurchaseNoAd->runAction(MoveTo::create(0.5f, Point(buttonPurchaseNoAd->getPositionX(), -200)));
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
listener = EventListenerCustom::create(EVENT_PURCHASED + "com.reallycsc.endlesslove.adremove", [=](EventCustom* event) {
m_pGameMediator->setIsAd(false);
m_pGameMediator->setIsGuidelineForever(true);
buttonPurchaseNoAd->runAction(MoveTo::create(0.5f, Point(buttonPurchaseNoAd->getPositionX(), -200)));
CSCClass::CSC_IOSHelper::GameCenter_checkAndUnlockAchievement("com.reallycsc.endlesslove.adremove");
//.........这里部分代码省略.........