facebook twitter hatena line email

Cocos2dx/Log

提供: 初心者エンジニアの簡易メモ
2018年9月25日 (火) 14:39時点におけるAdmin (トーク | 投稿記録)による版 (ログをformに入れる)

移動: 案内検索

サンプル

log("hoge");
int _int = 1;
log("%i", _int);
const char *str = "hogestr";
log("%s", str);
double _double = 1.0001;
log("%f", _double); // 1.000100;

android studioで確認した場合

02-20 16:59:52.260 18958-18981/com.example.helloworld D/cocos2d-x debug info: hoge

error: cannot convert 'const char*' to 'double' for argument '1' to 'double log(double)'エラーとなる場合

以下を記述するか

USING_NS_CC;

coocs2d::を追加する

cocos2d::log("hoge");

ログカスタム関数

addLog("init");
void HelloWorld::addLog(const std::string str) {
   log("%s", str.c_str());
}

ログカスタム関数に数字などを入れる

int cnt = 10;
const char* chr = "a";
addLog("id=" + label->getString());
addLog("count=" + StringUtils::toString(cnt)); // int
addLog("log=" + std::string(chr); // char

ログをformに入れる

logLabel = Label::createWithTTF("GNSAdSDK RewardVideoAd\ngejge", "fonts/arial.ttf", 6);
logLabel->setPosition(Vec2(origin.x + visibleSize.width/2,
                           origin.y + visibleSize.height * 0.5f - logLabel->getContentSize().height));
logLabel->setWidth(visibleSize.width * 0.9f);
this->addChild(logLabel, 1);
void HelloWorld::addLog(const std::string str) {
    log("%s", str.c_str());
    logLabel->setString(str + "\n" + logLabel->getString());
}