Skip to content

Instantly share code, notes, and snippets.

View kobayashi-poppin-games's full-sized avatar

k.kobayashi kobayashi-poppin-games

View GitHub Profile
@kobayashi-poppin-games
kobayashi-poppin-games / gist:8952315
Created February 12, 2014 09:21
ラベルにタッチ判定を追加する処理
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);
@kobayashi-poppin-games
kobayashi-poppin-games / gist:8952311
Created February 12, 2014 09:20
統一初期化構文は使えない
// std::vectorのように書きたいところだが
std::vector<Sprite*> sprites = {sprite1, sprite2, sprite3};
// こうはいかない
cocos2d::Vector<Sprite*> sprites = {sprite, sprite2, sprite3};
@kobayashi-poppin-games
kobayashi-poppin-games / gist:8952310
Created February 12, 2014 09:20
[]オペレータが使えない
// atメソッドでのアクセスは可能だが
Node *n1 = getChildren().at(1);
// []オペレータは定義されておらず、使えない
Node *n2 = getChildren()[2];
@kobayashi-poppin-games
kobayashi-poppin-games / gist:8952301
Created February 12, 2014 09:19
x座標が100より大きい子ノードを探す
find_if(getChildren().begin(),
getChildren().end(),
[](Node* x)->bool { return x->getPosition().x > 100; } );
@kobayashi-poppin-games
kobayashi-poppin-games / gist:8952289
Last active August 29, 2015 13:56
子ノードのすべてのタグを表示
for(auto node : getChildren()) {
log("Node tag = %d", node->getTag() );
}
@kobayashi-poppin-games
kobayashi-poppin-games / gist:8951732
Last active August 29, 2015 13:56
ボタンを押すとシーンを遷移する
auto button = MenuItemFont::create("BUTTON", [&](Object* sender) {
Scene *scene = Scene::create();
Director::getInstance()->replaceScene(scene);
});
Menu *menu = Menu::createWithItem(button);
addChild(menu);