facebook twitter hatena line email

Cocos2dx/Label

提供: 初心者エンジニアの簡易メモ
2017年4月12日 (水) 17:02時点におけるAdmin (トーク | 投稿記録)による版 (Labelの定義)

移動: 案内検索

ラベル追加

Hello Worldを24pxで中央に表示する

-Classes/HelloWorldScene.cpp

#include <string>
std::string text = "Hello World";
auto label = Label::createWithTTF(text, "fonts/Marker Felt.ttf", 24);
label->setPosition(Vec2(origin.x + visibleSize.width/2,
                           origin.y + visibleSize.height - label->getContentSize().height));
this->addChild(label, 1);

フォントはResources/fonts/内にある

日本語について

  • デフォルトのFelt.ttfは日本語に対応してない

Labelの定義

static Label * createWithTTF(const std::string& text, const std::string& fontFilePath, float fontSize);

数字をLavelに表示

std::string text = "origin.x=" + StringUtils::toString(origin.x);
auto labelResult = Label::createWithTTF(text, "fonts/Marker Felt.ttf", 8);