facebook twitter hatena line email

「Cocos2dx/Log」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ログカスタム関数)
(ログカスタム関数)
行18: 行18:
  
 
==ログカスタム関数==
 
==ログカスタム関数==
 +
addLog("init");
 +
void HelloWorld::addLog(const std::string str) {
 +
    log("%s", str.c_str());
 +
}
 +
 +
==ログカスタム関数に数字などを入れる==
 
  int cnt = 10;
 
  int cnt = 10;
 
  const char* chr = "a";
 
  const char* chr = "a";
addLog("init");
 
 
  addLog("id=" + label->getString());
 
  addLog("id=" + label->getString());
 
  addLog("count=" + StringUtils::toString(cnt)); // int
 
  addLog("count=" + StringUtils::toString(cnt)); // int
 
  addLog("log=" + std::string(chr); // char
 
  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->setContentSize(Size(visibleSize.width/2, visibleSize.height /2));
 +
this->addChild(logLabel, 1);
 
  void HelloWorld::addLog(const std::string str) {
 
  void HelloWorld::addLog(const std::string str) {
    log("%s", str.c_str());
+
    log("%s", str.c_str());
 +
    logLabel->setString(str + "\n" + logLabel->getString());
 
  }
 
  }

2018年9月25日 (火) 14:34時点における版

サンプル

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->setContentSize(Size(visibleSize.width/2, visibleSize.height /2));
this->addChild(logLabel, 1);
void HelloWorld::addLog(const std::string str) {
    log("%s", str.c_str());
    logLabel->setString(str + "\n" + logLabel->getString());
}