This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto button = MenuItemFont::create("BUTTON", [&](Object* sender) { | |
Scene *scene = Scene::create(); | |
Director::getInstance()->replaceScene(scene); | |
}); | |
Menu *menu = Menu::createWithItem(button); | |
addChild(menu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(auto node : getChildren()) { | |
log("Node tag = %d", node->getTag() ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_if(getChildren().begin(), | |
getChildren().end(), | |
[](Node* x)->bool { return x->getPosition().x > 100; } ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// atメソッドでのアクセスは可能だが | |
Node *n1 = getChildren().at(1); | |
// []オペレータは定義されておらず、使えない | |
Node *n2 = getChildren()[2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// std::vectorのように書きたいところだが | |
std::vector<Sprite*> sprites = {sprite1, sprite2, sprite3}; | |
// こうはいかない | |
cocos2d::Vector<Sprite*> sprites = {sprite, sprite2, sprite3}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto label = LabelTTF::create("LABEL", "Arial", 24); | |
auto listener = EventListenerTouchOneByOne::create(); | |
listener->onTouchBegan = [](Touch* touch, Event* event) { | |
log("this is label"); | |
/*〜必要な処理〜*/ | |
return true; | |
}; | |
Director::getInstance()->getEventDispatcher() | |
->addEventListenerWithSceneGraphPriority(listener, label); |