您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx_lua_v3.7 open console

2015-07-26 21:43 483 查看
用lua_v3.2的时候,console是默认开启,下了最新的v3.7后,发现不开了,开关也不好找。

仔细观察工程目录,发现多了很多文件

SimulatorWin.h


原来是main.cpp --> AppDelegate

现在改成main.cpp --> SimulatorWin --> AppDelegate

SimulatorWin会先设置一些参数,比如是否开始log,将log输出到某一个文件

ProjectConfig.h


位于\frameworks\cocos2d-x\tools\simulator\libsimulator\lib\ProjectConfig目下,SimulatorWin的配置都会从这里读取

如果在运行程序的时候,传递一些参数,这些参数将会被在SimulatorWin进行设置

比如要开启log

前置条件

打开
game01\frameworks\runtime-src\Classes\ide-support\CodeIDESupport.h



#define CC_CODE_IDE_DEBUG_SUPPORT 0


改成
#define CC_CODE_IDE_DEBUG_SUPPORT 1


方法1

可以在SimulatorWin的run函数里添加

_project.setWriteDebugLogToFile(true);


当然,能不改源码是最好的

方法2

打开cmd,进入projectDir/simulator/win32,打如下命令
game01.exe -write-debug-log debug.log


以上两种操作都会将Log输出到debug.log文件里面

关于运行winSimulator可以设置的参数

void ProjectConfig::parseCommandLine(const vector<string> &args)
{
auto it = args.begin();
while (it != args.end())
{
string arg = *it;

if (arg.compare("-workdir") == 0)
{
++it;
if (it == args.end()) break;
setProjectDir(*it);
if (_writablePath.length() == 0) setWritablePath(*it);
}
else if (arg.compare("-writable-path") == 0)
{
++it;
if (it == args.end()) break;
setWritablePath(*it);
}
else if (arg.compare("-entry") == 0)
{
++it;
if (it == args.end()) break;
setScriptFile(*it);
}
else if (arg.compare("-landscape") == 0)
{
setFrameSize(cocos2d::Size(DEFAULT_HEIGHT, DEFAULT_WIDTH));
}
else if (arg.compare("-portrait") == 0)
{
setFrameSize(cocos2d::Size(DEFAULT_WIDTH, DEFAULT_HEIGHT));
}
else if (arg.compare("-resolution") == 0)
{
++it;
if (it == args.end()) break;
const string& sizeStr(*it);
size_t pos = sizeStr.find('x');
int width = 0;
int height = 0;
if (pos != sizeStr.npos && pos > 0)
{
string widthStr, heightStr;
widthStr.assign(sizeStr, 0, pos);
heightStr.assign(sizeStr, pos + 1, sizeStr.length() - pos);
width = atoi(widthStr.c_str());
height = atoi(heightStr.c_str());
setFrameSize(cocos2d::Size(width, height));
}
}
else if (arg.compare("-scale") == 0)
{
++it;
if (it == args.end()) break;
float scale = atof((*it).c_str());
setFrameScale(scale);
}
else if (arg.compare("-write-debug-log") == 0)
{
++it;
if (it == args.end()) break;
setDebugLogFilePath((*it));
setWriteDebugLogToFile(true);
}
else if (arg.compare("-console") == 0)
{
++it;
if (it == args.end()) break;
if ((*it).compare("enable") == 0)
{
setShowConsole(true);
}
else
{
setShowConsole(false);
}
}
else if (arg.compare("-position") == 0)
{
++it;
if (it == args.end()) break;
const string& posStr(*it);
size_t pos = posStr.find(',');
int x = 0;
int y = 0;
if (pos != posStr.npos && pos > 0)
{
string xStr, yStr;
xStr.assign(posStr, 0, pos);
yStr.assign(posStr, pos + 1, posStr.length() - pos);
x = atoi(xStr.c_str());
y = atoi(yStr.c_str());
setWindowOffset(cocos2d::Vec2(x, y));
}
}
else if (arg.compare("-debugger") == 0)
{
++it;
if (it == args.end()) break;
if ((*it).compare("codeide") == 0)
{
setDebuggerType(kCCRuntimeDebuggerCodeIDE);
}
else if ((*it).compare("studio") == 0)
{
setDebuggerType(kCCRuntimeDebuggerStudio);
}
}
else if (arg.compare("-app-menu") == 0)
{
_isAppMenu = true;
}
else if (arg.compare("-resize-window") == 0)
{
_isResizeWindow = true;
}
else if (arg.compare("-retina-display") == 0)
{
_isRetinaDisplay = true;
}
else if (arg.compare("-port") == 0)
{
CCLOG("TODO:");
}
else if (arg.compare("-listen") == 0)
{
++it;
setBindAddress((*it));
}
else if (arg.compare("-search-path") == 0)
{
++it;
vector<string> pathes = split((*it), ';');
setSearchPath(pathes);
}

++it;
}
}


以上代码位于
\frameworks\cocos2d-x\tools\simulator\libsimulator\lib\ProjectConfig


除了可以打开log外,还可以设置运行窗口的大小
game01.exe -resolution 480x320


需要注意的是480和320之间的是小写字母x,而不是*
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: