How to add/set object or cast ccColor3B to CCObject* ?

How to add/set object or cast ccColor3B to CCObject* ?
0.0 0


Hi, I just wondering how can I setObject of a color data into a CCDictionary?
I dont think I can cast ccColor3B into CCObject*

I tried CCData but I cant pass the pointer (of a ccColor3B) to it since it is not an object but just a struct.

Do I need to create my own color class? I know it will work if I just create my own color class but I just wondering if there is a simpler way.




Yes, create own color class or functions to read/write color into string, e.g

CCString *colorToString(const ccColor3B &color)
    return CCString::createWithFormat("{%d,%d,%d}", (int)color.r, (int)color.g, (int)color.b);

ccColor3B parseColor(const CCString *string)
    int r = 0, g = 0, b = 0;
    scanf("{%d,%d,%d}", string->m_sString.c_str(), &r, &g, &b);
    ccColor3B color;
    color.r = r;
    color.g = g;
    color.b = b;
    return color;


On the other hand You should be able to cast ccColor3B* to void* and then to CCObject*


Thanks Sergey. I guess making your own class is better.

And Pawel how can I create ccColor3B*? Since ccColor3B is just a struct?

Anyway thanks.