Game Development Reference
In-Depth Information
The spriteFrame.texture.contentSize is the total size of the texture in points.
This size will be consistent across all devices, regardless of whether the texture is the tab-
lethd version or the regular phone version. The sprite frame's rect defines the position and
size within the texture where this particular image is located. The originalSize prop-
erty refers to the untrimmed size.
Within the for loop in Listing 10-12 , each vertex color is set to a full white, opaque col-
or. If they weren't set to this color, you wouldn't be able to see the texture you're going to
draw. Feel free to try different colors and transparency.
Each body's position is first offset by the sprite frame's origin. Since OpenGL draws tex-
tures upside down, and internally Cocos2D maps most commands directly to OpenGL (or
Metal) commands, the y coordinate needs to be subtracted from the sprite frame's origin
plus its height. Otherwise, the player would be drawn upside down.
The resulting position is assigned to the texCoord1 field of the vertex. But first, it is
converted from absolute coordinates in points to percentage values in the range of 0.0 to
1.0. The MIN/MAX macros ensure the values aren't outside of this range, which would
likely provoke a crash. Once more, the y coordinate needs to be upside down—subtracting
the result from 1.0 inverses the texture coordinate.
After all nine _numVertices have been processed, there's but one last vertex. The val-
ues are simply copied from the second vertex (at index 1), thus creating a duplicate of ver-
tex #2, which was shown in Figure 10-6 as the last vertex in the _vertices array.
This concludes the setup of vertices and texture coordinates.
Not Trimming Sprite Sheet Sprites
While we're on the topic of sprite frames, you should uncheck the Trim sprites check box
for the Global Sprite Sheet in SpriteBuilder, as shown in Figure 10-7 .
Search WWH ::




Custom Search