ioscocos2d-iphonensstringuicolorccnode

Convert UIColor to CCNodeColor


As I'm passing NSStrings into UIColors and what not, for my cocos2d application, I am storing a colour for the scene's background in a UIColor variable, however would like to then convert the UIColor to a CCNodeColor variable? Obviously, the sample code below is wrong but that's where I'm at right now.

NSString *backgroundColour = [backgroundColourArray objectAtIndex:randomIndex];
CIColor *coreColour = [CIColor colorWithString:backgroundColour];
UIColor *colour = [UIColor colorWithCIColor:coreColour];
CCNodeColor *background = [UIColor colour]; // Problems arise here

Solution

  • Try to create CCNodeColor like this:

    CCNodeColor *background = [[CCNodeColor alloc] initWithColor:[CCColor colorWithUIColor:colour]];