本文整理汇总了C++中CCTexture2D::getContentSizeInPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTexture2D::getContentSizeInPixels方法的具体用法?C++ CCTexture2D::getContentSizeInPixels怎么用?C++ CCTexture2D::getContentSizeInPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTexture2D
的用法示例。
在下文中一共展示了CCTexture2D::getContentSizeInPixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//-------------------------------------------------------------------------------------------------
// loads MD2 model
bool CCMD2Model::Load(char *filename, char *textureName)
{
//FILE *filePtr; // file pointer
unsigned long fileLen = 0; // length of model file
//char *buffer; // file buffer
modelHeader_t *modelHeader; // model header
stIndex_t *stPtr; // texture data
frame_t *frame; // frame data
kmVec3 *pointListPtr; // index variable
mesh_t *triIndex, *bufIndexPtr; // index variables
int i, j; // index variables
// open the model file
std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(filename);
//unsigned long nSize = 0;
unsigned char* buffer = CCFileUtils::sharedFileUtils()->getFileData(path.c_str(), "rb", &fileLen);
if (buffer == NULL)
return false;
//const char *path = filename;//GetPath(filename);
/*filePtr = fopen(path, "rb");
if (filePtr == NULL)
return false;*/
// find length of file
//fseek(filePtr, 0, SEEK_END);
//fileLen = ftell(filePtr);
//fseek(filePtr, 0, SEEK_SET);
//// read entire file into buffer
//buffer = (char*)malloc(fileLen + 1);
//fread(buffer, sizeof(char), fileLen, filePtr);
// extract model file header from buffer
modelHeader = (modelHeader_t*)buffer;
// allocate memory for model data
mModel = (modelData_t*)malloc(sizeof(modelData_t));
if (mModel == NULL)
{
CC_SAFE_DELETE_ARRAY(buffer);
return false;
}
// allocate memory for all vertices used in model, including animations
mModel->pointList = (kmVec3 *)malloc(sizeof(kmVec3)*modelHeader->numXYZ * modelHeader->numFrames);
// store vital model data
mModel->numPoints = modelHeader->numXYZ;
mModel->numFrames = modelHeader->numFrames;
mModel->frameSize = modelHeader->framesize;
// loop number of frames in model file
for(j = 0; j < modelHeader->numFrames; j++)
{
// offset to the points in this frame
frame = (frame_t*)&buffer[modelHeader->offsetFrames + modelHeader->framesize * j];
// calculate the point positions based on frame details
pointListPtr = (kmVec3 *)&mModel->pointList[modelHeader->numXYZ * j];
for(i = 0; i < modelHeader->numXYZ; i++)
{
pointListPtr[i].x = frame->scale[0] * frame->fp[i].v[0] + frame->translate[0];
pointListPtr[i].y = frame->scale[1] * frame->fp[i].v[1] + frame->translate[1];
pointListPtr[i].z = frame->scale[2] * frame->fp[i].v[2] + frame->translate[2];
}
}
CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addImage(textureName);
if (tex)
mModel->modelTex = tex;
else
{
free(mModel);
mModel = NULL;
CC_SAFE_DELETE_ARRAY(buffer);
//free(buffer);
return false;
}
CCSize size = tex->getContentSizeInPixels();
float texWidth = size.width;
float texHeight = size.height;
// allocate memory for the model texture coordinates
mModel->st = (texCoord_t*)malloc(sizeof(texCoord_t)*modelHeader->numST);
// store number of texture coordinates
mModel->numST = modelHeader->numST;
//.........这里部分代码省略.........
示例2: Load
bool CScutAniGroup::Load(const char* sprName)
{
if (NULL == sprName)
{
return false;
}
string spr = sprName;
if (spr.size() == 0)
{
return false;
}
if (this->m_sprName.size() > 0)
{
return this->m_sprName == spr;
}
this->m_sprName = sprName;
spr += ".spr";
spr = SPRITE_FILE_DIR + spr;
spr = CFileHelper::getPath(spr.c_str());
char cMode[3] = {'r', 'b', 0};
unsigned long uSize = 0;
unsigned char* pBuf = (unsigned char*)CFileHelper::getFileData(spr.c_str(), cMode, &uSize);
CSpriteFileStream fileSpr;
if (fileSpr.Write((const char*)pBuf, uSize) == 0)
{
delete[] pBuf;
return false;
}
delete[] pBuf;
fileSpr.SetPosition(0);
int tableSize = fileSpr.ReadByte();
this->m_vTileTable.assign(tableSize, ScutTileTable());
for (int i = 0; i < tableSize; i++)
{
ScutTileTable& tt = this->m_vTileTable[i];
tt.imgIndex = fileSpr.ReadByte();
tt.clip.origin.x = fileSpr.ReadShort();
tt.clip.origin.y = fileSpr.ReadShort();
tt.clip.size.width = fileSpr.ReadShort();
tt.clip.size.height = fileSpr.ReadShort();
}
double pixcelFactor = 1.0;
int imgSize = fileSpr.ReadByte();
CCTexture2D* pTex = NULL;
this->m_vTexture.assign(imgSize, ReplaceTexture());
string texFile;
for (int j = 0; j < imgSize; j++)
{
ReplaceTexture& texture = this->m_vTexture[j];
fileSpr.ReadUTF(texFile);
texFile = SPRITE_IMAGE_DIR + texFile;
texFile = CFileHelper::getPath(texFile.c_str());
pTex = CCTextureCache::sharedTextureCache()->addImage(texFile.c_str());
assert(pTex != NULL);
CC_SAFE_RETAIN(pTex);
texture.pTex = pTex;
texture.replaceIndex = fileSpr.ReadByte();
texture.dFactor = (double)pTex->getContentSizeInPixels().width / (double)fileSpr.ReadShort();
// 取第一张图片的缩放比例作为动画整体的估计值
if (0 == j)
{
pixcelFactor = texture.dFactor;
}
}
this->caculateTileTableTextureCoord();
CScutAniData* pAniData = NULL;
CScutFrame* pFrame = NULL;
CScutTile* pTile = NULL;
int aniSize = fileSpr.ReadByte();
this->m_vAniData.assign(aniSize, pAniData);
for (int m = 0; m < aniSize; m++)
{
pAniData = new CScutAniData;
this->m_vAniData[m] = pAniData;
pAniData->m_tContentSize.width = fileSpr.ReadShort() * pixcelFactor;
pAniData->m_tContentSize.height = fileSpr.ReadShort() * pixcelFactor;
pAniData->m_anchorX = fileSpr.ReadShort();
pAniData->m_anchorY = fileSpr.ReadShort();
pAniData->m_type = fileSpr.ReadByte();
int frameSize = fileSpr.ReadByte();
pAniData->m_vFrame.assign(frameSize, pFrame);
//.........这里部分代码省略.........