Daniel Bramhall
Daniel Bramhall

Reputation: 57

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

Upvotes: 0

Views: 132

Answers (1)

Alexander Tkachenko
Alexander Tkachenko

Reputation: 3281

Try to create CCNodeColor like this:

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

Upvotes: 1

Related Questions