「Cocos2dx/ScrollView」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
(→サンプル) |
||
行2: | 行2: | ||
下半分に複数行ラベルを表示 | 下半分に複数行ラベルを表示 | ||
auto visibleSize = Director::getInstance()->getVisibleSize(); | auto visibleSize = Director::getInstance()->getVisibleSize(); | ||
− | Vec2 origin = Director::getInstance()->getVisibleOrigin(); | + | Vec2 origin = Director::getInstance()->getVisibleOrigin(); // origin.x = 0; origin.y = 25 |
− | std::string text = | + | 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/Marker Felt.ttf", 10); | auto labelResult = Label::createWithTTF(text, "fonts/Marker Felt.ttf", 10); | ||
labelResult->setPosition(Vec2(origin.x + labelResult->getContentSize().width / 2 | labelResult->setPosition(Vec2(origin.x + labelResult->getContentSize().width / 2 |
2017年4月13日 (木) 14:08時点における版
サンプル
下半分に複数行ラベルを表示
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/Marker Felt.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);