CCColor Class Reference
Inherits from | NSObject |
---|---|
Declared in | CCColor.h |
Overview
A CCColor object represents color and sometimes opacity (alpha value) for use with Cocos2D objects.
It is the Cocos2D equivalent of UIColor respectively NSColor.
Creating a Color from RGB(A) Components
+ colorWithWhite:alpha:
Creates and returns a color object using the specified opacity and grayscale values.
+ (CCColor *)colorWithWhite:(float)white alpha:(float)alpha
Parameters
white |
The grayscale value of the color object, specified as a value from 0.0 to 1.0. |
---|---|
alpha |
The opacity value of the color object, specified as a value from 0.0 to 1.0. |
Return Value
The color object.
Declared In
CCColor.h
+ colorWithRed:green:blue:alpha:
Creates and returns a color object using the specified opacity and RGBA component values.
+ (CCColor *)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha
Parameters
red |
The red component of the color object, specified as a value from 0.0 to 1.0. |
---|---|
green |
The green component of the color object, specified as a value from 0.0 to 1.0. |
blue |
The blue component of the color object, specified as a value from 0.0 to 1.0. |
alpha |
The opacity value of the color object, specified as a value from 0.0 to 1.0. |
Return Value
The color object.
Declared In
CCColor.h
+ colorWithRed:green:blue:
Creates and returns a color object using the specified opacity and RGB component values. Alpha will default to 1.0.
+ (CCColor *)colorWithRed:(float)red green:(float)green blue:(float)blue
Parameters
red |
The red component of the color object, specified as a value from 0.0 to 1.0. |
---|---|
green |
The green component of the color object, specified as a value from 0.0 to 1.0. |
blue |
The blue component of the color object, specified as a value from 0.0 to 1.0. |
Return Value
The color object.
Declared In
CCColor.h
– colorWithAlphaComponent:
Creates and returns a color object that has the same color space and component values as the receiver, but has the specified alpha component.
- (CCColor *)colorWithAlphaComponent:(float)alpha
Parameters
alpha |
The opacity value of the new CCColor object. |
---|
Return Value
The color object.
Declared In
CCColor.h
– initWithWhite:alpha:
Initializes and returns a color object using the specified opacity and grayscale values.
- (CCColor *)initWithWhite:(float)white alpha:(float)alpha
Parameters
white |
The grayscale value of the color object, specified as a value from 0.0 to 1.0. |
---|---|
alpha |
The opacity value of the color object, specified as a value from 0.0 to 1.0. |
Return Value
An initialized color object.
Declared In
CCColor.h
– initWithRed:green:blue:alpha:
Initializes and returns a color object using the specified opacity and RGBA component values.
- (CCColor *)initWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha
Parameters
red |
The red component of the color object, specified as a value from 0.0 to 1.0. |
---|---|
green |
The green component of the color object, specified as a value from 0.0 to 1.0. |
blue |
The blue component of the color object, specified as a value from 0.0 to 1.0. |
alpha |
The opacity value of the color object, specified as a value from 0.0 to 1.0. |
Return Value
An initialized color object.
Declared In
CCColor.h
– initWithRed:green:blue:
Initializes and returns a color object using the specified opacity and RGB component values. Alpha will default to 1.0.
- (CCColor *)initWithRed:(float)red green:(float)green blue:(float)blue
Parameters
red |
The red component of the color object, specified as a value from 0.0 to 1.0. |
---|---|
green |
The green component of the color object, specified as a value from 0.0 to 1.0. |
blue |
The blue component of the color object, specified as a value from 0.0 to 1.0. |
Return Value
An initialized color object.
Declared In
CCColor.h
Creating a Color with CGColor/UIColor
+ colorWithCGColor:
Creates and returns a color object using the specified Quartz color reference.
+ (CCColor *)colorWithCGColor:(CGColorRef)cgColor
Parameters
cgColor |
A reference to a Quartz color. |
---|
Return Value
The color object.
Declared In
CCColor.h
– initWithCGColor:
Initializes and returns a color object using the specified Quartz color reference.
- (CCColor *)initWithCGColor:(CGColorRef)cgColor
Parameters
cgColor |
A reference to a Quartz color. |
---|
Return Value
An initialized color object.
Declared In
CCColor.h
Getting Preset Colors
+ blackColor
Returns a color object whose RGB values are 0.0, 1.0, and 1.0 and whose alpha value is 1.0.
+ (CCColor *)blackColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ darkGrayColor
Returns a color object whose grayscale value is 1/3 and whose alpha value is 1.0.
+ (CCColor *)darkGrayColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ lightGrayColor
Returns a color object whose grayscale value is 2/3 and whose alpha value is 1.0.
+ (CCColor *)lightGrayColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ whiteColor
Returns a color object whose grayscale value is 1.0 and whose alpha value is 1.0.
+ (CCColor *)whiteColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ grayColor
Returns a color object whose grayscale value is 0.5 and whose alpha value is 1.0.
+ (CCColor *)grayColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ redColor
Returns a color object whose RGB values are 1.0, 0.0, and 0.0 and whose alpha value is 1.0.
+ (CCColor *)redColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ greenColor
Returns a color object whose RGB values are 0.0, 1.0, and 0.0 and whose alpha value is 1.0.
+ (CCColor *)greenColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ blueColor
Returns a color object whose RGB values are 0.0, 0.0, and 1.0 and whose alpha value is 1.0.
+ (CCColor *)blueColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ cyanColor
Returns a color object whose RGB values are 0.0, 1.0, and 1.0 and whose alpha value is 1.0..
+ (CCColor *)cyanColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ yellowColor
Returns a color object whose RGB values are 1.0, 1.0, and 0.0 and whose alpha value is 1.0.
+ (CCColor *)yellowColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ magentaColor
Returns a color object whose RGB values are 1.0, 0.0, and 1.0 and whose alpha value is 1.0.
+ (CCColor *)magentaColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ orangeColor
Returns a color object whose RGB values are 1.0, 0.5, and 0.0 and whose alpha value is 1.0..
+ (CCColor *)orangeColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ purpleColor
Returns a color object whose RGB values are 0.5, 0.0, and 0.5 and whose alpha value is 1.0.
+ (CCColor *)purpleColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ brownColor
Returns a color object whose RGB values are 0.6, 0.4, and 0.2 and whose alpha value is 1.0.
+ (CCColor *)brownColor
Return Value
The CCColor object.
Declared In
CCColor.h
+ clearColor
Returns a color object whose RGB values are 0.0, 0.0, and 0.0 and whose alpha value is 0.0.
+ (CCColor *)clearColor
Return Value
The CCColor object.
Declared In
CCColor.h
Converting Colors
CGColor
The Quartz color reference that corresponds to the CCColor color.
@property (nonatomic, readonly) CGColorRef CGColor
Declared In
CCColor.h
UIColor
The UIColor color reference that corresponds to the CCColor color.
@property (nonatomic, readonly) *UIColor
Declared In
CCColor.h
NSColor
The NSColor color reference that corresponds to the CCColor color.
@property (nonatomic, readonly) *NSColor
Declared In
CCColor.h
Retrieving RGBA Components
– getRed:green:blue:alpha:
Retrieves the color’s RGBA components, storing them in the passed-in parameters.
- (BOOL)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha
Parameters
red |
Red color value. |
---|---|
green |
Green color value. |
blue |
Blue color value. |
alpha |
Alpha value. |
Return Value
YES
Discussion
Usage example, the values will be in the float variables after the method call:
float r, g, b, a;
[color getRed:&r green:&g blue:&b alpha:&a];
Declared In
CCColor.h
– getWhite:alpha:
Retrieves the color’s brightness and alpha components, storing them in the passed-in parameters.
- (BOOL)getWhite:(float *)white alpha:(float *)alpha
Parameters
white |
Approximated brightness value (average of R+B+G). |
---|---|
alpha |
Alpha value. |
Return Value
YES
Discussion
Usage example, the values will be in the float variables after the method call:
float w, a;
[color getWhite:&w alpha:&a];
Declared In
CCColor.h
Color Helpers
RGBA_Properties Methods
– isEqualToColor:
Compares specified color to current color and returns whether they are identical.
- (BOOL)isEqualToColor:(CCColor *)color
Parameters
color |
Color to compare. |
---|
Return Value
YES if colors are identical.
Declared In
CCColor.h