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

cocos2dx 入门练习杂记 - 备用

2013-11-27 14:50 225 查看
菜单方式创建按钮

CCLabelTTF *label = CCLabelTTF::create("BTN-TEST",  "Arial", 20); // 创建按钮显示文本
CCMenuItemLabel *myBtn
= CCMenuItemLabel::create(label, this, menu_selector( HelloWorld::btnTest ) );  // 创建菜单按钮,用menu_selector绑定处理函数
myBtn->setPosition(CCPointZero);   // 设定按钮位置基准点为 屏幕中心
myBtn->setPosition( ccp( 0, 0 ) ); // 设定按钮位置
CCMenu* pMyMenu = CCMenu::create( myBtn, NULL); // 把按钮添加到 菜单中
this->addChild( pMyMenu, 1);// 设置按钮所在图层


按钮文字设置颜色

ccColor3B myColor;
myColor.r = 225;
myColor.g = 0;
myColor.b = 1;
myBtn->setColor( myColor );


# cocos2dx 代码中调用的图片文件,默认路径为工程同级目录 的[ Resources ]文件夹中,而不是工程目录内

VS运行,中文乱码
因为Cocos2d-x使用的是UTF-8编码,VS默认GB2312
转换函数网上有很多,这里保留一份。

char* GToU(const char* strGB2312)
{
int iLen = MultiByteToWideChar(CP_ACP, 0, strGB2312, -1, NULL, 0);

wchar_t* wstr = new wchar_t[iLen+1];
memset(wstr, 0, iLen+1);
MultiByteToWideChar(CP_ACP, 0, strGB2312, -1, wstr, iLen);
iLen = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);

char* strUTF8 = new char[iLen+1];
memset(strUTF8, 0, iLen+1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, strUTF8, iLen, NULL, NULL);
if(wstr) delete[] wstr;

return strUTF8;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: