# 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.

## Tasks

### Creating a CCColor Object from Component Values

- `+ colorWithWhite:alpha:`
- `+ colorWithRed:green:blue:alpha:`
- `+ colorWithRed:green:blue:`
- `+ colorWithCGColor:`
- `– colorWithAlphaComponent:`
- `+ colorWithUIColor:`

### Initializing a CCColor Object

- `– initWithWhite:alpha:`
- `– initWithRed:green:blue:alpha:`
- `– initWithRed:green:blue:`
- `– initWithCGColor:`
- `– initWithUIColor:`

### Creating a CCColor with Preset Component Values

- `+ blackColor`
- `+ darkGrayColor`
- `+ lightGrayColor`
- `+ whiteColor`
- `+ grayColor`
- `+ redColor`
- `+ greenColor`
- `+ blueColor`
- `+ cyanColor`
- `+ yellowColor`
- `+ magentaColor`
- `+ orangeColor`
- `+ purpleColor`
- `+ brownColor`
- `+ clearColor`

### Accessing Color Attributes

- `CGColor` property
- `UIColor` property
- `NSColor` property

### Color Helpers

- `– interpolateTo:alpha:`

## Properties

### CGColor

The Quartz color reference that corresponds to the CCColor color.

`@property (nonatomic, readonly) CGColorRef CGColor`

#### Declared In

`CCColor.h`

### NSColor

The NSColor color reference that corresponds to the CCColor color.

`@property (nonatomic, readonly) *NSColor`

#### Declared In

`CCColor.h`

### UIColor

The UIColor color reference that corresponds to the CCColor color.

`@property (nonatomic, readonly) *UIColor`

#### Declared In

`CCColor.h`

## Class Methods

### 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`

### 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`

### 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`

### 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`

### 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`

### 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`

### colorWithUIColor:

Converts a UIColor object to its CCColor equivalent.

`+ (CCColor *)colorWithUIColor:(UIColor *)color`

#### Parameters

color

  UIColor object.

#### Return Value

The color object.

#### Declared In

`CCColor.h`

### 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`

### 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`

### 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`

### 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`

### 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`

### 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`

### 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`

### 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`

### 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`

### 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`

## Instance Methods

### 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`

### 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`

### 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`

### 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`

### initWithUIColor:

Initializes and returns a UIColor object to its CCColor equivalent.

`- (CCColor *)initWithUIColor:(UIColor *)color`

#### Parameters

color

  UIColor object.

#### Return Value

An initialized 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`

### interpolateTo:alpha:

Linearly interpolate from this color to ‘toColor’. Parameter alpha is normalised

`- (CCColor *)interpolateTo:(CCColor *)toColor alpha:(float)alpha`

#### Parameters

toColor

  Color to interpolate to.

alpha

  Normalised alpha opacity of toColor.

#### Return Value

The interpolated color.

#### Declared In

`CCColor.h`