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); }总结
以上是内存溢出为你收集整理的[cocos2d-x]string 转 Color全部内容,希望文章能够帮你解决[cocos2d-x]string 转 Color所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)