「Cocos2dx/ScrollView」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
|||
行5: | 行5: | ||
Vec2 origin = Director::getInstance()->getVisibleOrigin(); // origin.x = 0; origin.y = 25 | Vec2 origin = Director::getInstance()->getVisibleOrigin(); // origin.x = 0; origin.y = 25 | ||
std::string text = "Hello World\nHello World2\n2\n2\n2\n2\n2\n2\n3\n3\n3\n3\n3\n3\n3\n4\n4\n5\n5\n5\n"; | std::string text = "Hello World\nHello World2\n2\n2\n2\n2\n2\n2\n3\n3\n3\n3\n3\n3\n3\n4\n4\n5\n5\n5\n"; | ||
− | auto labelResult = Label::createWithTTF(text, "fonts/ | + | auto labelResult = Label::createWithTTF(text, "fonts/arial.ttf", 10); |
labelResult->setPosition(Vec2(origin.x + labelResult->getContentSize().width / 2, | labelResult->setPosition(Vec2(origin.x + labelResult->getContentSize().width / 2, | ||
labelResult->getContentSize().height / 2)); | labelResult->getContentSize().height / 2)); |
2017年4月13日 (木) 15:53時点における版
サンプル
下半分に複数行ラベルを表示 -HelloworldScene.cpp
auto visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); // origin.x = 0; origin.y = 25 std::string text = "Hello World\nHello World2\n2\n2\n2\n2\n2\n2\n3\n3\n3\n3\n3\n3\n3\n4\n4\n5\n5\n5\n"; auto labelResult = Label::createWithTTF(text, "fonts/arial.ttf", 10); labelResult->setPosition(Vec2(origin.x + labelResult->getContentSize().width / 2, labelResult->getContentSize().height / 2)); ScrollView* scroll = ScrollView::create(); scroll->setContentSize(Size(labelResult->getContentSize().width, visibleSize.height / 2)); scroll->setInnerContainerSize(Size(labelResult->getContentSize().width, labelResult->getContentSize().height)); scroll->setDirection(ScrollView::Direction::VERTICAL); // 縦方向だけにスクロール scroll->setPosition(Vec2(origin.x - scroll->getContentSize().width / 2 + visibleSize.width / 2, origin.y)); scroll->addChild(labelResult, 1); addChild(scroll);