[cocos2d-x]string 转 Color
发布时间:2020-12-14 20:10:28 所属栏目:百科 来源:网络整理
导读:static int toColor (const char* value,int index) { char digits[3]; char *error; int color; if (strlen(value) != 8) return -1; value += index * 2; digits[0] = *value; digits[1] = *(value + 1); digits[2] = ' '; color = (int)strtoul(digits,e
static int toColor (const char* value,int index) { char digits[3]; char *error; int color; if (strlen(value) != 8) return -1; value += index * 2; digits[0] = *value; digits[1] = *(value + 1); digits[2] = ' '; color = (int)strtoul(digits,&error,16); if (*error != 0) return -1; return color; } cocos2d::Color4B stringToColor(std::string &str) { if (str.length() != 8) { return cocos2d::Color4B::WHITE; } const char *ch = str.c_str(); GLubyte r = (GLubyte)toColor(ch,0); GLubyte g = (GLubyte)toColor(ch,1); GLubyte b = (GLubyte)toColor(ch,2); GLubyte a = (GLubyte)toColor(ch,3); return cocos2d::Color4B(r,g,b,a); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |