Cocos2d—X游戏开发之VS2010 控制台输出中文,模拟器中文乱码问题解决(十八)
首先,先解决第一个问题,我们使用VS2010开发的时候,调试的时候,中文打印出来都是乱码,这个问题很纠结。
如下图:
CCLOG("cclog: 测试使用标签的自动换行和个别字体大写");LOGNEWLINE;
输出结果如下图:
<dict>cocos2d.x.version: 2.1rc0-x-2.1.4cocos2d.x.compiled_with_profiler: falsecocos2d.x.compiled_with_gl_state_cache: truegl.vendor: NVIDIA Corporationgl.renderer: GeForce 310M/PCIe/SSE2gl.version: 3.3.0gl.max_texture_size: 8192gl.max_texture_units: 96gl.supports_PVRTC: falsegl.supports_NPOT: truegl.supports_BGRA8888: falsegl.supports_discard_framebuffer: falsegl.supports_vertex_array_object: true</dict>cclog: ?????????????????к?????????д
这是很大的一个问题,是吗?英语不是很熟练的小伙伴们?
不得不说,VS2010这个开发工具没说的,真是开发者的杯具开始。尤其是对我使用MAC非常熟悉的人来说。
好的,废话不说,看下怎么使用控制台来调试我们的代码,能够正常输入中文。
这里需要配置main.c,通过它来调出控制台输出中文,但是有一点限制,就是必须使用cout 或者 printf ,而不能使用CCLog。
直接贴出代码:
#include "main.h"#include "AppDelegate.h"#include "CCEGLView.h"#include "net/NetWork.h"#include "adapter/RouterAdapter.h"USING_NS_CC;#define USE_WIN32_CONSOLEint APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine);#ifdef USE_WIN32_CONSOLEAllocConsole();freopen("CONIN$","r",stdin);freopen("CONOUT$","w",stdout);freopen("CONOUT$","w",stderr);#endif // create the application instance CCEGLView* eglView = CCEGLView::sharedOpenGLView(); eglView->setViewName("MT"); //eglView->setFrameSize(480,320); return CCApplication::sharedApplication()->run();#ifdef USE_WIN32_CONSOLEFreeConsole();#endif}
通过这个USE_WIN32_CONSOLE来实现我们的代码调试。测试代码如下
CCLOG("cclog: 测试使用标签的自动换行和个别字体大写");LOGNEWLINE;printf("printf: 测试使用标签的自动换行和个别字体大写");LOGNEWLINE;
VS2010输出窗口如下:
<dict>cocos2d.x.version: 2.1rc0-x-2.1.4cocos2d.x.compiled_with_profiler: falsecocos2d.x.compiled_with_gl_state_cache: truegl.vendor: NVIDIA Corporationgl.renderer: GeForce 310M/PCIe/SSE2gl.version: 3.3.0gl.max_texture_size: 8192gl.max_texture_units: 96gl.supports_PVRTC: falsegl.supports_NPOT: truegl.supports_BGRA8888: falsegl.supports_discard_framebuffer: falsegl.supports_vertex_array_object: true</dict>cclog: ?????????????????к?????????д
为什么只是输出CCLog,printf 呢?
看下控制台,如下:
然后是第二个问题,模拟器上竟然也是乱码!!!如果英语很好,在调试的时候,可以使用英文代替,但是到了开发的时候了,模拟器上中文竟然也是乱码??!
这是造的。
测试代码:
CCLabelTTF *testLabel = CCLabelTTF::create("测试使用标签的自动换行和个别字体大写,test","Zapfino",30);testLabel->setPosition(ccp(visibleSize.width*0.5,visibleSize.height*0.2));testLabel->setColor(ccc3(200,200,200));this->addChild(testLabel,1);
模拟器运行如下图:
有了时间在写,很快。