本文整理汇总了C++中CCSpriteFrame::initWithTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteFrame::initWithTexture方法的具体用法?C++ CCSpriteFrame::initWithTexture怎么用?C++ CCSpriteFrame::initWithTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCSpriteFrame
的用法示例。
在下文中一共展示了CCSpriteFrame::initWithTexture方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: frameWithTexture
CCSpriteFrame* CCSpriteFrame::frameWithTexture(CCTexture2D* pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
{
CCSpriteFrame *pSpriteFrame = new CCSpriteFrame();;
pSpriteFrame->initWithTexture(pobTexture, rect, rotated, offset, originalSize);
pSpriteFrame->autorelease();
return pSpriteFrame;
}
示例2: createWithTexture
CCSpriteFrame* CCSpriteFrame::createWithTexture(CCTexture2D *pobTexture, const CCRect& rect)
{
CCSpriteFrame *pSpriteFrame = new CCSpriteFrame();;
pSpriteFrame->initWithTexture(pobTexture, rect);
CC_SAFE_AUTORELEASE(pSpriteFrame);
return pSpriteFrame;
}
示例3: copyWithZone
CCObject* CCSpriteFrame::copyWithZone(CCZone *pZone)
{
CCSpriteFrame *pCopy = new CCSpriteFrame();
pCopy->initWithTexture(m_pobTexture, m_obRectInPixels, m_bRotated, m_obOffsetInPixels, m_obOriginalSizeInPixels);
return pCopy;
}
示例4: create
CCSpriteFrame* CCSpriteFrame::create(CCTexture2D* pobTexture, const CCRect& rect, bool rotated, const CCPoint& offset, const CCSize& originalSize)
{
CCSpriteFrame *pSpriteFrame = new CCSpriteFrame();;
pSpriteFrame->initWithTexture(pobTexture, rect, rotated, offset, originalSize);
pSpriteFrame->autorelease();
return pSpriteFrame;
}
示例5: copyWithZone
CCObject* CCSpriteFrame::copyWithZone(CCZone *pZone)
{
CC_UNUSED_PARAM(pZone);
CCSpriteFrame *pCopy = new CCSpriteFrame();
pCopy->initWithTexture(m_pobTexture, m_obRect, m_bRotated, m_obOffset, m_obOriginalSize);
return pCopy;
}
示例6: CCSpriteFrame
void SkeletonCocos2D::Load(const char* skelFilename, const char* texFilenameDesc, const char* texFilename, const char* useSkeletonName)
{
//////////////////////////////////////////////////////////////////////////
unsigned long _size=0;
char *_pFileContent = (char*)CCFileUtils::sharedFileUtils()->getFileData(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(skelFilename) , "r", &_size);
TiXmlDocument _document;
_document.Parse(_pFileContent, 0, TIXML_ENCODING_UTF8);
m_resource=new Skeleton2DResourceAvatar;
m_resource->LoadAll(_document.RootElement());
m_skeleton->AttachResource(m_resource->GetSkeleton(useSkeletonName));
//////////////////////////////////////////////////////////////////////////
char *texDescContent = (char*)CCFileUtils::sharedFileUtils()->getFileData(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(texFilenameDesc) , "r", &_size);
TiXmlDocument xmlTexDesc;
xmlTexDesc.Parse(texDescContent, 0, TIXML_ENCODING_UTF8);
m_textureDesc = m_resource->AddTextureResource(xmlTexDesc.RootElement());
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(texFilename));
for (Skeleton2DResourceTexture::Name2SubTexture::iterator it = m_textureDesc->m_subTexs.begin()
;it != m_textureDesc->m_subTexs.end();++it)
{
const RString& subTexName=it->first;
Skeleton2DResourceSubTexture& subData=it->second;
CCSpriteFrame* spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(texture,
CCRectMake(subData.x, subData.y, subData.width, subData.height),
false,
//CCPointMake(subData.pivotX,subData.pivotY),
CCPointMake(0,0),
CCSizeMake((float)subData.width, (float)subData.height)
);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(spriteFrame,subTexName.c_str());
}
m_batchSprite = CCSpriteBatchNode::create(texFilename);
addChild(m_batchSprite);
UpdateBoneImages();
this->scheduleUpdate();
}
示例7: addSpriteFramesWithDictionary
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
{
/*
Supported Zwoptex Formats:
ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
*/
CCDictionary<std::string, CCObject*> *metadataDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
CCDictionary<std::string, CCObject*> *framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
int format = 0;
// get the format
if(metadataDict != NULL)
{
format = atoi(valueForKey("format", metadataDict));
}
// check the format
CCAssert(format >=0 && format <= 3, "");
framesDict->begin();
std::string key = "";
CCDictionary<std::string, CCObject*> *frameDict = NULL;
while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
{
CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
if (spriteFrame)
{
continue;
}
if(format == 0)
{
float x = (float)atof(valueForKey("x", frameDict));
float y = (float)atof(valueForKey("y", frameDict));
float w = (float)atof(valueForKey("width", frameDict));
float h = (float)atof(valueForKey("height", frameDict));
float ox = (float)atof(valueForKey("offsetX", frameDict));
float oy = (float)atof(valueForKey("offsetY", frameDict));
int ow = atoi(valueForKey("originalWidth", frameDict));
int oh = atoi(valueForKey("originalHeight", frameDict));
// check ow/oh
if(!ow || !oh)
{
CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
}
// abs ow/oh
ow = abs(ow);
oh = abs(oh);
// create frame
spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(pobTexture,
CCRectMake(x, y, w, h),
false,
CCPointMake(ox, oy),
CCSizeMake((float)ow, (float)oh)
);
}
else if(format == 1 || format == 2)
{
CCRect frame = CCRectFromString(valueForKey("frame", frameDict));
bool rotated = false;
// rotation
if (format == 2)
{
rotated = atoi(valueForKey("rotated", frameDict)) == 0 ? false : true;
}
CCPoint offset = CCPointFromString(valueForKey("offset", frameDict));
CCSize sourceSize = CCSizeFromString(valueForKey("sourceSize", frameDict));
// create frame
spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(pobTexture,
frame,
rotated,
offset,
sourceSize
);
} else
if (format == 3)
{
// get values
CCSize spriteSize = CCSizeFromString(valueForKey("spriteSize", frameDict));
CCPoint spriteOffset = CCPointFromString(valueForKey("spriteOffset", frameDict));
CCSize spriteSourceSize = CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
CCRect textureRect = CCRectFromString(valueForKey("textureRect", frameDict));
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
// get aliases
CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
CCMutableArray<CCString*>::CCMutableArrayIterator iter;
CCString * frameKey = new CCString(key.c_str());
for (iter = aliases->begin(); iter != aliases->end(); ++iter)
//.........这里部分代码省略.........
示例8: addSpriteFrameFromDict
void SpriteFrameCacheHelper::addSpriteFrameFromDict(CCDictionary* dictionary, CCTexture2D *pobTexture, const char *_imagePath)
{
/*
Supported Zwoptex Formats:
ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
*/
CCDictionary *metadataDict = (CCDictionary*)dictionary->objectForKey("metadata");
CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames");
int format = 0;
// get the format
if(metadataDict != NULL)
{
format = metadataDict->valueForKey("format")->intValue();
}
// check the format
CCAssert(format >=0 && format <= 3, "format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");
CCDictElement* pElement = NULL;
CCDICT_FOREACH(framesDict, pElement)
{
CCDictionary* frameDict = (CCDictionary*)pElement->getObject();
std::string spriteFrameName = pElement->getStrKey();
m_Display2ImageMap[spriteFrameName] = _imagePath;
//CCLog("spriteFrameName : %s, imagePath : %s", spriteFrameName.c_str(), _imagePath);
CCSpriteFrame* spriteFrame = (CCSpriteFrame*)CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrameName.c_str());
if (spriteFrame)
{
continue;
}
if(format == 0)
{
float x = frameDict->valueForKey("x")->floatValue();
float y = frameDict->valueForKey("y")->floatValue();
float w = frameDict->valueForKey("width")->floatValue();
float h = frameDict->valueForKey("height")->floatValue();
float ox = frameDict->valueForKey("offsetX")->floatValue();
float oy = frameDict->valueForKey("offsetY")->floatValue();
int ow = frameDict->valueForKey("originalWidth")->intValue();
int oh = frameDict->valueForKey("originalHeight")->intValue();
// check ow/oh
if(!ow || !oh)
{
CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
}
// abs ow/oh
ow = abs(ow);
oh = abs(oh);
// create frame
spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(pobTexture,
CCRectMake(x, y, w, h),
false,
CCPointMake(ox, oy),
CCSizeMake((float)ow, (float)oh)
);
}
else if(format == 1 || format == 2)
{
CCRect frame = CCRectFromString(frameDict->valueForKey("frame")->getCString());
bool rotated = false;
// rotation
if (format == 2)
{
rotated = frameDict->valueForKey("rotated")->boolValue();
}
CCPoint offset = CCPointFromString(frameDict->valueForKey("offset")->getCString());
CCSize sourceSize = CCSizeFromString(frameDict->valueForKey("sourceSize")->getCString());
// create frame
spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(pobTexture,
frame,
rotated,
offset,
sourceSize
);
}
else if (format == 3)
{
}
// add sprite frame
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(spriteFrame, spriteFrameName.c_str());
spriteFrame->release();
}
示例9: cacheFramesForPlist
bool CCPreLoad::cacheFramesForPlist(const char* plist, const char* textureFileName)
{
bool ret = false;
do{
//private权限不好继承,直接挑出来改,Zwoptex.swf 1.0的version
CCTexture2D *pobTexture = CCTextureCache::sharedTextureCache()->addImage(textureFileName);
if(pobTexture == NULL)
break;
string pszPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist);
CCDictionary *dictionary = CCDictionary::createWithContentsOfFileThreadSafe(pszPath.c_str());
CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames");
int format = 0;
CCDictElement* pElement = NULL;
CCDICT_FOREACH(framesDict, pElement)
{
CCDictionary* frameDict = (CCDictionary*)pElement->getObject();
std::string spriteFrameName = pElement->getStrKey();
CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrameName.c_str());
if (spriteFrame)
{
continue;
}
int format = 0;//就只挑这个
if(format == 0)
{
float x = frameDict->valueForKey("x")->floatValue();
float y = frameDict->valueForKey("y")->floatValue();
float w = frameDict->valueForKey("width")->floatValue();
float h = frameDict->valueForKey("height")->floatValue();
float ox = frameDict->valueForKey("offsetX")->floatValue();
float oy = frameDict->valueForKey("offsetY")->floatValue();
int ow = frameDict->valueForKey("originalWidth")->intValue();
int oh = frameDict->valueForKey("originalHeight")->intValue();
// check ow/oh
if(!ow || !oh)
{
CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
}
// abs ow/oh
ow = abs(ow);
oh = abs(oh);
// create frame
spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(pobTexture,
CCRectMake(x, y, w, h),
false,
CCPointMake(ox, oy),
CCSizeMake((float)ow, (float)oh)
);
}
// add sprite frame
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(spriteFrame, spriteFrameName.c_str());
m_tmpFrames.insert(make_pair(spriteFrameName,spriteFrame));
spriteFrame->release();
}
dictionary->release();
ret = true;
}while(0);