1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#ifndef __CCTEXTURE_ATLAS_H__ #define __CCTEXTURE_ATLAS_H__ //用到的头文件 #include #include "ccTypes.h" #include "CCObject.h" #include "ccConfig.h" //使用Cocos2d命名空间 namespace cocos2d
{ class CCTexture2D; //CCTextureAtlas由CCObject派生而来 class CC_DLL CCTextureAtlas
: public CCObject { protected:
//使用此大图中的图块的精灵对应的三角形索引数组的指针
GLushort *m_pIndices; #if CC_USES_VBO
//如果使用Vertex Buffer Object(VBO:使用显存而非内存存储顶点缓冲数据,大大提高效率),建立VBO句柄数组,第一个元素存顶点数组的句柄,第二个元素存索引数组句柄
GLuint m_pBuffersVBO[2];
//标记是否更新需要更新的图块信息。当你新加入了图块或者修改了图块,需要设置为true。
bool m_bDirty;
#endif // CC_USES_VBO
// CC_PROPERTY_READONLY宏为类定义变量及增加相应的get函数。
//当前使用图块的数量
CC_PROPERTY_READONLY(unsigned
int, m_uTotalQuads, TotalQuads)
//存储图块信息的数组容量
CC_PROPERTY_READONLY(unsigned
int, m_uCapacity, Capacity)
//设置所使用的大图纹理
CC_PROPERTY(CCTexture2D
*, m_pTexture, Texture)
//使用此大图的图块的所有精灵的顶点缓冲信息数组
CC_PROPERTY(ccV3F_C4B_T2F_Quad
*, m_pQuads, Quads)
public:
//构造
CCTextureAtlas();
//析构
virtual ~CCTextureAtlas();
//描述
char * description();
//静态函数:从文件中创建纹理,并初始化图块容量
static CCTextureAtlas
* textureAtlasWithFile(const
char* file ,
unsigned int capacity);
//同上,只是非静态函数。作者提示不能重复调用,否则会造成内存泄漏。
bool initWithFile(const
char* file,
unsigned int capacity);
//静态函数:从贴图中创建纹理,并初始化图块容量
static CCTextureAtlas
* textureAtlasWithTexture(CCTexture2D
*texture, unsigned
int capacity);
//同上,只是非静态函数。作者提示不能重复调用,否则会造成内存泄漏。
bool initWithTexture(CCTexture2D
*texture, unsigned
int capacity);
//通过索引值找到对应的图块顶点缓冲数据并用新数据修改它,由CCSprite实例对象在变换顶点信息时调用。
void updateQuad(ccV3F_C4B_T2F_Quad* quad,
unsigned int index);
//通过索引值找到对应的图块顶点缓冲数据,并在其之前插入一个新的图块。
void insertQuad(ccV3F_C4B_T2F_Quad* quad,
unsigned int index);
//通过索引值找到对应的图块顶点缓冲数据,并把它插入另一个图块之前。
void insertQuadFromIndex(unsigned
int fromIndex, unsigned
int newIndex);
//移除指定位置的图块顶点缓冲数据.
void removeQuadAtIndex(unsigned
int index);
//清空所有的图块顶点缓冲数据。
void removeAllQuads();
//重新设置图块顶点缓冲数组的容量
bool resizeCapacity(unsigned
int n);
//绘制指定的图块顶点缓冲
void drawNumberOfQuads(unsigned
int n);
//绘制从指定的图块起后面的N个图块
void drawNumberOfQuads(unsigned
int n, unsigned
int start);
//绘制所有的图块顶点缓冲
void drawQuads(); private:
//初始化索引缓冲数据
void initIndices(); }; }//namespace cocos2d
#endif //__CCTEXTURE_ATLAS_H__
|