本文整理汇总了C++中CCSpriteFrame::getOriginalSizeInPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteFrame::getOriginalSizeInPixels方法的具体用法?C++ CCSpriteFrame::getOriginalSizeInPixels怎么用?C++ CCSpriteFrame::getOriginalSizeInPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCSpriteFrame
的用法示例。
在下文中一共展示了CCSpriteFrame::getOriginalSizeInPixels方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onMyHeadImgLoaded
void HFHeadImgNode::onMyHeadImgLoaded(CCObject* object)
{
// 本地上传的头像
CCString* image = dynamic_cast<CCString*>(object);
if (image == NULL) {
return;
}
CCSpriteFrame* pFrame = getSpriteFrame(image->getCString());
if (pFrame == NULL)
{
int removeState = remove(image->getCString());
if (removeState==0 && m_retry<6)//重试5次
{
autoDefaultEnable tmp;
m_retry++;
HFUrlImageCache::shared()->loadImageAsync(m_headImgUrl, CCCallFuncO::create(this, callfuncO_selector(HFHeadImgNode::onMyheadImgBack), NULL));
}
return;
}
m_retry = 0;
CCSize ccsz = pFrame->getOriginalSizeInPixels();
m_myPortrait->setDisplayFrame(pFrame);
m_myPortrait->setScale(m_scale * (90.0f/ccsz.width));
m_headImgUrl.clear();
}
示例2: getSpriteFrame
void HFHeadImgNode::onMyheadImgBack2(cocos2d::CCObject *pObj)
{
CCString* image = dynamic_cast<CCString*>(pObj);
if (image == NULL) {
return;
}
CCSpriteFrame* pFrame = getSpriteFrame(image->getCString());
if (pFrame == NULL)
{
int removeState = remove(image->getCString());
if (removeState==0 && m_retry<6)//重试5次
{
autoDefaultEnable tmp;
m_retry++;
HFUrlImageCache::shared()->loadImageAsync(m_headImgUrl, CCCallFuncO::create(this, callfuncO_selector(HFHeadImgNode::onMyheadImgBack2), NULL));
}
return;
}
autoDefaultEnable tmp;
m_retry = 0;
CCSize ccsz = pFrame->getOriginalSizeInPixels();
CCSprite* head = CCSprite::createWithSpriteFrame(pFrame);
head->setAnchorPoint(ccp(0.5, 0.5));
if (m_size > 1E-6)
{
CCCommonUtils::setSpriteMaxSize(head, m_size, true);
}
else
{
head->setScale(m_scale);
}
m_myRenderTexture = CCRenderTexture::create(m_cSize.width, m_cSize.height);
m_myRenderTexture->setAnchorPoint(ccp(0.5, 0.5));
ccBlendFunc cbf = {GL_ZERO,GL_ONE_MINUS_SRC_ALPHA};
auto spr = CCLoadSprite::createSprite(m_backImg.c_str());
auto bgCircle = CCLoadSprite::createSprite(m_renderImg.c_str());
spr->setScale(1);
spr->setPosition(ccp(m_cSize.width / 2, m_cSize.height / 2));
if (!m_imgPoint.equals(CCPointZero))
{
head->setPosition(m_imgPoint);
}
bgCircle->setPosition(ccp(m_cSize.width / 2, m_cSize.height / 2));
bgCircle->setBlendFunc(cbf);
m_myRenderTexture->begin();
spr->visit();
head->visit();
bgCircle->visit();
m_myRenderTexture->end();
if (m_clearNode) {
m_myParentNode->removeAllChildrenWithCleanup(true);
}
m_myParentNode->addChild(m_myRenderTexture);
m_headImgUrl.clear();
}
示例3:
CCNode *APSSprite::createNode() {
CCNode *node = APSGraphic::createNode();
APSImageHolder *ih = this->getImageHolder();
CCSize contentSize;
CCSize targetSize = APSPlatform::sharedPlatform()->convertSizeToPixels(this->getSize());
if (ih) {
this->m_spriteNode = new CCSprite;
if (this->getIsAnimatable()) {
// Create animation sprite
APSSpriteSheetHolder *sh = (APSSpriteSheetHolder *)ih;
CCSpriteFrame *spriteFrame = sh->getCCSpriteFrameAtIndex(((APSGraphicGroup *)this->getParent())->getDisplayedFrameIndex());
#if COCOS2D_VERSION >= 0x00020000
CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::createWithTexture(ih->getTexture(), sh->getCount());
#else
CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::batchNodeWithTexture(ih->getTexture(), sh->getCount());
#endif//APS_SKIP
this->m_node->addChild(spriteSheet);
this->m_spriteNode->initWithSpriteFrame(spriteFrame);
spriteSheet->addChild(this->m_spriteNode);
CCSize size = this->m_spriteNode->getContentSize();
contentSize = APSPlatform::sharedPlatform()->convertSizeToPixels(size);
} else {
// Check if there is a sprite frame in sprite frame cache.
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(this->getImageHolder()->getRuntimeFilename().c_str());
if (frame) {
// Use the sprite frame
this->m_spriteNode->initWithSpriteFrame(frame);
contentSize = frame->getOriginalSizeInPixels();
node->addChild(this->m_spriteNode);
} else {
// Normal sprite
this->m_spriteNode->initWithTexture(ih->getTexture());
contentSize = ih->getTexture()->getContentSizeInPixels();
node->addChild(this->m_spriteNode);
}
}
// scale the sprite to match the sizes of texture and sprite
this->m_spriteNode->setScaleX(targetSize.width/contentSize.width);
this->m_spriteNode->setScaleY(targetSize.height/contentSize.height);
}
return node;
}
示例4: onFBImageLoaded
void HFHeadImgNode::onFBImageLoaded(CCObject* object)
{
//FaceBook头像
CCString* image = dynamic_cast<CCString*>(object);
if (image == NULL) {
return;
}
CCSpriteFrame* spFrame = getSpriteFrame(image->getCString());
if (spFrame == NULL)
{
return;
}
CCSize ccsz = spFrame->getOriginalSizeInPixels();
m_myPortrait->setDisplayFrame(spFrame);
m_myPortrait->setScale(1.7f * (50.0f/ccsz.width)*m_scale);
m_headImgUrl.clear();
}
示例5: onMyheadImgBack
void HFHeadImgNode::onMyheadImgBack(cocos2d::CCObject *pObj)
{
CCString* image = dynamic_cast<CCString*>(pObj);
if (image == NULL) {
return;
}
CCSpriteFrame* pFrame = getSpriteFrame(image->getCString());
if (pFrame == NULL)
{
int removeState = remove(image->getCString());
if (removeState==0 && m_retry<6)//重试5次
{
m_retry++;
autoDefaultEnable tmp;
HFUrlImageCache::shared()->loadImageAsync(m_headImgUrl, CCCallFuncO::create(this, callfuncO_selector(HFHeadImgNode::onMyheadImgBack), NULL));
}
return;
}
m_retry = 0;
CCSize ccsz = pFrame->getOriginalSizeInPixels();
autoDefaultEnable tmp;
CCSprite* head = CCSprite::createWithSpriteFrame(pFrame);
if (m_clearNode)
{
m_myParentNode->removeAllChildren();
}
m_myParentNode->addChild(head);
if (m_size > 1E-6)
{
CCCommonUtils::setSpriteMaxSize(head, m_size, true);
}
else
{
head->setScale(m_scale);
}
if (!m_imgPoint.equals(CCPointZero))
{
head->setPosition(m_imgPoint);
}
m_headImgUrl.clear();
}
示例6: CCImage
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_CCImage_1richlabel_nativeGetSpriteFrameInfo
(JNIEnv * env, jclass clazz, jstring jPlist, jstring jAtlas, jstring jImageName, jobject jFrame) {
// get c string
const char* plist = (const char*)env->GetStringUTFChars(jPlist, NULL);
const char* atlas = (const char*)env->GetStringUTFChars(jAtlas, NULL);
const char* imageName = (const char*)env->GetStringUTFChars(jImageName, NULL);
// get sprite frame
CLBitmapDC& bitmapDC = CLBitmapDC::sharedCLBitmapDC();
CCSpriteFrameCache* fc = CCSpriteFrameCache::sharedSpriteFrameCache();
if(!fc->spriteFrameByName(imageName)) {
if(bitmapDC.m_decryptFunc) {
// load encryptd data
unsigned long len;
char* data = (char*)CCFileUtils::sharedFileUtils()->getFileData(atlas, "rb", &len);
// create texture
int decLen;
const char* dec = (*bitmapDC.m_decryptFunc)(data, (int)len, &decLen);
CCImage* image = new CCImage();
image->initWithImageData((void*)dec, decLen);
image->autorelease();
CCTexture2D* tex = CCTextureCache::sharedTextureCache()->addUIImage(image, atlas);
// add
fc->addSpriteFramesWithFile(plist, tex);
// free
if(data != dec)
free((void*)dec);
free(data);
} else {
fc->addSpriteFramesWithFile(plist, atlas);
}
}
CCSpriteFrame* frame = fc->spriteFrameByName(imageName);
// get java frame info
jclass frameClass = env->FindClass("org/cocos2dx/lib/CCImage_richlabel$AtlasFrame");
jfieldID fid_x = env->GetFieldID(frameClass, "x", "I");
jfieldID fid_y = env->GetFieldID(frameClass, "y", "I");
jfieldID fid_w = env->GetFieldID(frameClass, "w", "I");
jfieldID fid_h = env->GetFieldID(frameClass, "h", "I");
jfieldID fid_offsetX = env->GetFieldID(frameClass, "offsetX", "I");
jfieldID fid_offsetY = env->GetFieldID(frameClass, "offsetY", "I");
jfieldID fid_sourceWidth = env->GetFieldID(frameClass, "sourceWidth", "I");
jfieldID fid_sourceHeight = env->GetFieldID(frameClass, "sourceHeight", "I");
jfieldID fid_rotated = env->GetFieldID(frameClass, "rotated", "Z");
// copy frame info to java object
const CCSize& sourceSize = frame->getOriginalSizeInPixels();
bool rotated = frame->isRotated();
const CCRect& frameRect = frame->getRectInPixels();
const CCPoint& offset = frame->getOffsetInPixels();
env->SetIntField(jFrame, fid_x, (int)frameRect.origin.x);
env->SetIntField(jFrame, fid_y, (int)frameRect.origin.y);
env->SetIntField(jFrame, fid_w, (int)frameRect.size.width);
env->SetIntField(jFrame, fid_h, (int)frameRect.size.height);
env->SetIntField(jFrame, fid_offsetX, (int)offset.x);
env->SetIntField(jFrame, fid_offsetY, (int)offset.y);
env->SetIntField(jFrame, fid_sourceWidth, (int)sourceSize.width);
env->SetIntField(jFrame, fid_sourceHeight, (int)sourceSize.height);
env->SetBooleanField(jFrame, fid_rotated, rotated);
// release
env->DeleteLocalRef(frameClass);
env->ReleaseStringUTFChars(jPlist, plist);
env->ReleaseStringUTFChars(jAtlas, atlas);
env->ReleaseStringUTFChars(jImageName, imageName);
}