当前位置:编程学习 > wap >>

Cocos2d—X游戏开发之VS2010 控制台输出中文,模拟器中文乱码问题解决

如下图:
 
[cpp]  
CCLOG("cclog: 测试使用标签的自动换行和个别字体大写");LOGNEWLINE;  
 
输出结果如下图:
 
[cpp] 
<dict>  
    cocos2d.x.version: 2.1rc0-x-2.1.4  
    cocos2d.x.compiled_with_profiler: false  
    cocos2d.x.compiled_with_gl_state_cache: true  
    gl.vendor: NVIDIA Corporation  
    gl.renderer: GeForce 310M/PCIe/SSE2  
    gl.version: 3.3.0  
    gl.max_texture_size: 8192  
    gl.max_texture_units: 96  
    gl.supports_PVRTC: false  
    gl.supports_NPOT: true  
    gl.supports_BGRA8888: false  
    gl.supports_discard_framebuffer: false  
    gl.supports_vertex_array_object: true  
</dict>  
cclog: ?????????????????к?????????д  
 
 
这是很大的一个问题,是吗?英语不是很熟练的小伙伴们?
 
不得不说,VS2010这个开发工具没说的,真是开发者的杯具开始。尤其是对我使用MAC非常熟悉的人来说。
 
好的,废话不说,看下怎么使用控制台来调试我们的代码,能够正常输入中文。
 
这里需要配置main.c,通过它来调出控制台输出中文,但是有一点限制,就是必须使用cout 或者 printf ,而不能使用CCLog。
 
直接贴出代码:
 
 
 
[cpp] 
#include "main.h"  
#include "AppDelegate.h"  
#include "CCEGLView.h"  
#include "net/NetWork.h"  
#include "adapter/RouterAdapter.h"  
  
USING_NS_CC;  
  
#define USE_WIN32_CONSOLE  
  
int APIENTRY _tWinMain(HINSTANCE hInstance,  
                       HINSTANCE hPrevInstance,  
                       LPTSTR    lpCmdLine,  
                       int       nCmdShow)  
{  
    UNREFERENCED_PARAMETER(hPrevInstance);  
    UNREFERENCED_PARAMETER(lpCmdLine);  
  
#ifdef USE_WIN32_CONSOLE  
    AllocConsole();  
    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_CONSOLE  
    FreeConsole();  
#endif  
  
}  
 
通过这个USE_WIN32_CONSOLE来实现我们的代码调试。测试代码如下
 
[cpp]  
CCLOG("cclog: 测试使用标签的自动换行和个别字体大写");LOGNEWLINE;  
printf("printf: 测试使用标签的自动换行和个别字体大写");LOGNEWLINE;  
 
VS2010输出窗口如下:
 
[cpp]  
<dict>  
    cocos2d.x.version: 2.1rc0-x-2.1.4  
    cocos2d.x.compiled_with_profiler: false  
    cocos2d.x.compiled_with_gl_state_cache: true  
    gl.vendor: NVIDIA Corporation  
    gl.renderer: GeForce 310M/PCIe/SSE2  
    gl.version: 3.3.0  
    gl.max_texture_size: 8192  
    gl.max_texture_units: 96  
    gl.supports_PVRTC: false  
    gl.supports_NPOT: true  
    gl.supports_BGRA8888: false  
    gl.supports_discard_framebuffer: false  
    gl.supports_vertex_array_object: true  
</dict>  
cclog: ?????????????????к?????????д  
为什么只是输出CCLog,printf 呢?
 
 
 
 
 
补充:移动开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,