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] = '\0'; 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); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。