Search code examples
xcodecocos2d-iphone

How to create an array of CCColor?


I use cocos2dV3 i create some color:

#define color_red ccc3(253, 93, 70)
#define color_green ccc3(138,233,145)
#define color_yellow ccc3(230,219,37)
#define color_violet ccc3 (153,93,181)
#define color_turquoise ccc3(138,188,255)
#define color_default ccc3(225,225,225)

How i can save it as array : NSArray , NSmutableAraay ... ?

 NSmutableArray * _arrColors =[[NSMutableArray alloc]init];

    [_arrColors addObject:color_turquoise];

When i create array it alway show errors : " Sending 'ccColor3B' (aka 'struct _ccColor3B') to parameter of incompatible type 'id'"

What i do worng ?


Solution

  • Using cocos2d does not relieve you of the responsibility of knowing Objective-C. A ccColor3B is not an object - it is a struct - so it cannot be put into an NSArray. You could, if you really want to do this, wrap it in an object, something like this perhaps:

    ccColor3B c = color_turquoise;
    [_arrColors addObject:[NSValue valueWithBytes:&c objCType:@encode(ccColor3B)]];