SPQuad Class Reference
| 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
-
– initWithWidth:height:color:premultipliedAlpha:Initializes a quad with a certain size and color. The
pmaparameter indicates how the colors of the object are stored. Designated Initializer. -
– initWithWidth:height:color:Initializes a quad with a certain size and color, using premultiplied alpha values.
-
– initWithWidth:height:Initializes a white quad with a certain size.
-
+ quadWithWidth:height:Factory method.
-
+ quadWithWidth:height:color:Factory method.
-
+ quadFactory method. Creates a 32x32 quad.
Methods
-
– setColor:ofVertex:Sets the color of a vertex.
-
– colorOfVertex:Returns the color of a vertex.
-
– setAlpha:ofVertex:Sets the alpha value of a vertex.
-
– alphaOfVertex:Returns the alpha value of a vertex.
-
– copyVertexDataTo:atIndex:Copies the raw vertex data to a VertexData instance.
-
– vertexDataDidChangeCall this method after manually changing the contents of ‘_vertexData’.
Properties
-
colorSets the colors of all vertices simultaneously. Returns the color of vertex ‘0’.
property -
premultipliedAlphaIndicates 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 -
tintedIndicates if any vertices have a non-white color or are not fully opaque. Any alpha value other than ‘1’ will also cause tinting.
property -
textureThe 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 colorDiscussion
Sets the colors of all vertices simultaneously. Returns the color of vertex ‘0’.
Declared In
SPQuad.hpremultipliedAlpha
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 premultipliedAlphaDiscussion
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.htexture
The texture that is displayed on the quad. For pure quads (no subclasses), this is always nil.
@property (nonatomic, readonly) SPTexture *textureDiscussion
The texture that is displayed on the quad. For pure quads (no subclasses), this is always nil.
Declared In
SPQuad.htinted
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 tintedDiscussion
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.hClass Methods
quad
Factory method. Creates a 32x32 quad.
+ (instancetype)quadDiscussion
Factory method. Creates a 32x32 quad.
Declared In
SPQuad.hInstance Methods
alphaOfVertex:
Returns the alpha value of a vertex.
- (float)alphaOfVertex:(int)vertexIDDiscussion
Returns the alpha value of a vertex.
Declared In
SPQuad.hcolorOfVertex:
Returns the color of a vertex.
- (uint)colorOfVertex:(int)vertexIDDiscussion
Returns the color of a vertex.
Declared In
SPQuad.hcopyVertexDataTo:atIndex:
Copies the raw vertex data to a VertexData instance.
- (void)copyVertexDataTo:(SPVertexData *)targetData atIndex:(int)targetIndexDiscussion
Copies the raw vertex data to a VertexData instance.
Declared In
SPQuad.hinitWithWidth:height:
Initializes a white quad with a certain size.
- (instancetype)initWithWidth:(float)width height:(float)heightDiscussion
Initializes a white quad with a certain size.
Declared In
SPQuad.hinitWithWidth:height:color:
Initializes a quad with a certain size and color, using premultiplied alpha values.
- (instancetype)initWithWidth:(float)width height:(float)height color:(uint)colorDiscussion
Initializes a quad with a certain size and color, using premultiplied alpha values.
Declared In
SPQuad.hinitWithWidth: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)pmaDiscussion
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.hsetAlpha:ofVertex:
Sets the alpha value of a vertex.
- (void)setAlpha:(float)alpha ofVertex:(int)vertexIDDiscussion
Sets the alpha value of a vertex.
Declared In
SPQuad.h