Inherits from SPDisplayObject : SPEventDispatcher : NSObject
Declared in SPQuad.h

Overview

An SPQuad represents a rectangle with a uniform color or a color gradient.

You can set one color per vertex. The colors will smoothly fade into each other over the area of the quad. To display a simple linear color gradient, assign one color to vertices 0 and 1 and another color to vertices 2 and 3.

The indices of the vertices are arranged like this:

0 - 1
| / |
2 - 3

Colors

Colors in Sparrow are defined as unsigned integers, that’s exactly 8 bit per color. The easiest way to define a color is by writing it as a hexadecimal number. A color has the following structure:

0xRRGGBB

That means that you can create the base colors like this:

0xFF0000 -> red
0x00FF00 -> green
0x0000FF -> blue

Other simple colors:

0x000000 or 0x0 -> black
0xFFFFFF        -> white
0x808080        -> 50% gray

If you’re not comfortable with that, there is also a utility macro available that takes the values for R, G and B separately:

uint red = SP_COLOR(255, 0, 0);

Tasks

Initialization

Methods

Properties

  •   color

    Sets the colors of all vertices simultaneously. Returns the color of vertex ‘0’.

    property
  •   premultipliedAlpha

    Indicates if the rgb values are stored premultiplied with the alpha value. This can have effect on the rendering. (Most developers don’t have to care, though.)

    property
  •   tinted

    Indicates if any vertices have a non-white color or are not fully opaque. Any alpha value other than ‘1’ will also cause tinting.

    property
  •   texture

    The texture that is displayed on the quad. For pure quads (no subclasses), this is always nil.

    property

Properties

color

Sets the colors of all vertices simultaneously. Returns the color of vertex ‘0’.

@property (nonatomic, assign) uint color

Discussion

Sets the colors of all vertices simultaneously. Returns the color of vertex ‘0’.

Declared In

SPQuad.h

premultipliedAlpha

Indicates if the rgb values are stored premultiplied with the alpha value. This can have effect on the rendering. (Most developers don’t have to care, though.)

@property (nonatomic, assign) BOOL premultipliedAlpha

Discussion

Indicates if the rgb values are stored premultiplied with the alpha value. This can have effect on the rendering. (Most developers don’t have to care, though.)

Declared In

SPQuad.h

texture

The texture that is displayed on the quad. For pure quads (no subclasses), this is always nil.

@property (nonatomic, readonly) SPTexture *texture

Discussion

The texture that is displayed on the quad. For pure quads (no subclasses), this is always nil.

Declared In

SPQuad.h

tinted

Indicates if any vertices have a non-white color or are not fully opaque. Any alpha value other than ‘1’ will also cause tinting.

@property (nonatomic, readonly) BOOL tinted

Discussion

Indicates if any vertices have a non-white color or are not fully opaque. Any alpha value other than ‘1’ will also cause tinting.

Declared In

SPQuad.h

Class Methods

quad

Factory method. Creates a 32x32 quad.

+ (instancetype)quad

Discussion

Factory method. Creates a 32x32 quad.

Declared In

SPQuad.h

quadWithWidth:height:

Factory method.

+ (instancetype)quadWithWidth:(float)width height:(float)height

Discussion

Factory method.

Declared In

SPQuad.h

quadWithWidth:height:color:

Factory method.

+ (instancetype)quadWithWidth:(float)width height:(float)height color:(uint)color

Discussion

Factory method.

Declared In

SPQuad.h

Instance Methods

alphaOfVertex:

Returns the alpha value of a vertex.

- (float)alphaOfVertex:(int)vertexID

Discussion

Returns the alpha value of a vertex.

Declared In

SPQuad.h

colorOfVertex:

Returns the color of a vertex.

- (uint)colorOfVertex:(int)vertexID

Discussion

Returns the color of a vertex.

Declared In

SPQuad.h

copyVertexDataTo:atIndex:

Copies the raw vertex data to a VertexData instance.

- (void)copyVertexDataTo:(SPVertexData *)targetData atIndex:(int)targetIndex

Discussion

Copies the raw vertex data to a VertexData instance.

Declared In

SPQuad.h

initWithWidth:height:

Initializes a white quad with a certain size.

- (instancetype)initWithWidth:(float)width height:(float)height

Discussion

Initializes a white quad with a certain size.

Declared In

SPQuad.h

initWithWidth:height:color:

Initializes a quad with a certain size and color, using premultiplied alpha values.

- (instancetype)initWithWidth:(float)width height:(float)height color:(uint)color

Discussion

Initializes a quad with a certain size and color, using premultiplied alpha values.

Declared In

SPQuad.h

initWithWidth:height:color:premultipliedAlpha:

Initializes a quad with a certain size and color. The pma parameter indicates how the colors of the object are stored. Designated Initializer.

- (instancetype)initWithWidth:(float)width height:(float)height color:(uint)color premultipliedAlpha:(BOOL)pma

Discussion

Initializes a quad with a certain size and color. The pma parameter indicates how the colors of the object are stored. Designated Initializer.

Declared In

SPQuad.h

setAlpha:ofVertex:

Sets the alpha value of a vertex.

- (void)setAlpha:(float)alpha ofVertex:(int)vertexID

Discussion

Sets the alpha value of a vertex.

Declared In

SPQuad.h

setColor:ofVertex:

Sets the color of a vertex.

- (void)setColor:(uint)color ofVertex:(int)vertexID

Discussion

Sets the color of a vertex.

Declared In

SPQuad.h

vertexDataDidChange

Call this method after manually changing the contents of ‘_vertexData’.

- (void)vertexDataDidChange

Discussion

Call this method after manually changing the contents of ‘_vertexData’.

Declared In

SPQuad.h