本文整理汇总了C++中CCSpriteFrameCache::addSpriteFrame方法的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteFrameCache::addSpriteFrame方法的具体用法?C++ CCSpriteFrameCache::addSpriteFrame怎么用?C++ CCSpriteFrameCache::addSpriteFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCSpriteFrameCache
的用法示例。
在下文中一共展示了CCSpriteFrameCache::addSpriteFrame方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CCRectMake
/* CCTableViewDelegate */
void
MCSkillLayer::tableCellTouched(CCTableView *table, CCTableViewCell *cell)
{
if (table != tableView_) {
return;
}
if (selectedCell_) {
selectedCell_->unselected();
}
selectedCell_ = dynamic_cast<MCTableViewTextFieldCell *>(cell);
selectedCell_->selected();
selectedSkill_ = dynamic_cast<MCSkill *>(skills_->objectAtIndex(cell->getIdx()));
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCSpriteFrame *frame = cache->spriteFrameByName(selectedSkill_->getName()->getCString());
if (! frame) {
frame = CCSpriteFrame::create(selectedSkill_->getIcon()->getCString(),
CCRectMake(0, 0, 64 / CC_CONTENT_SCALE_FACTOR(), 64 / CC_CONTENT_SCALE_FACTOR()));
cache->addSpriteFrame(frame, selectedSkill_->getName()->getCString());
}
icon_->setDisplayFrame(frame);
icon_->setVisible(true);
contentTableView_->reloadData();
contentTableView_->setVisible(true);
proficiency_->setVisible(true);
}
示例2: addSpritesToCache
static void addSpritesToCache()
{
#ifdef HAS_TEXTURE_PACKED
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCTexture2D* tex = CCTextureCache::sharedTextureCache()->addImage("sprites.png");
cache->addSpriteFrame(CCSpriteFrame::createWithTexture(tex, CCRectMake(0,0,320,480)), "background.png");
cache->addSpriteFrame(CCSpriteFrame::createWithTexture(tex, CCRectMake(336,16,256,108)), "cloud1.png");
cache->addSpriteFrame(CCSpriteFrame::createWithTexture(tex, CCRectMake(336,128,257,110)), "cloud2.png");
cache->addSpriteFrame(CCSpriteFrame::createWithTexture(tex, CCRectMake(336,240,252,119)), "cloud3.png");
cache->addSpriteFrame(CCSpriteFrame::createWithTexture(tex, CCRectMake(608,16,44,32)), "player.png");
cache->addSpriteFrame(CCSpriteFrame::createWithTexture(tex, CCRectMake(608,64,102,36)), "land1.png");
cache->addSpriteFrame(CCSpriteFrame::createWithTexture(tex, CCRectMake(608,128,90,32)), "land2.png");
#endif
}
示例3: init
bool FirstLayer::init()
{
if (!CCLayer::init())
{
return false;
}
CCSize s = CCDirector::sharedDirector()->getWinSize();
m_helpLayer = CCLayer::create();
m_scroll = CCScrollView::create();
m_scroll->setPosition(CCPointZero);
m_scroll->setContentOffset(CCPointZero);
m_scroll->setViewSize(CCSizeMake(640, 960));
m_scroll->setContentSize(CCSizeMake(640*3, 960));
m_scroll->setDirection(kCCScrollViewDirectionHorizontal);
m_scroll->setContainer(m_helpLayer);
m_scroll->setTouchEnabled(false);
m_scroll->setDelegate(this);
this->addChild(m_scroll);
char buf[30];
for (int i = 1; i <= 3; ++ i)
{
sprintf(buf,"first%d.png",i);
CCSprite *sprite = CCSprite::create(buf);
sprite->setPosition(ccp(s.width * (i-0.5f), s.height / 2));
m_helpLayer->addChild(sprite);
}
CCSpriteFrameCache *pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
pCache->addSpriteFrame(CCSpriteFrame::create(PIC_POINT_NORMAL,CCRectMake(0, 0, 15, 15)),PIC_POINT_NORMAL);
pCache->addSpriteFrame(CCSpriteFrame::create(PIC_POINT_SELECTED,CCRectMake(0, 0, 15, 15)),PIC_POINT_SELECTED);
for (int i = 1; i <= 3; ++ i)
{
CCSprite *pPoint = CCSprite::createWithSpriteFrameName(PIC_POINT_NORMAL);
pPoint->setTag(i);
pPoint->setPosition(ccp(s.width/2 + 30 * (i-2), 100));
this->addChild(pPoint);
}
CCSprite *pPoint = (CCSprite *)this->getChildByTag(1);
pPoint->setDisplayFrame(pCache->spriteFrameByName(PIC_POINT_SELECTED));
m_nCurPage = 1;
return true;
}
示例4: CCRectMake
void
MCBackpack::loadIcons()
{
/* 道具图片加进缓存 */
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCSpriteFrame *pobFrame;
float contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
CCRect iconRect = CCRectMake(0, 0, 64 / contentScaleFactor, 64 / contentScaleFactor);
pobFrame = CCSpriteFrame::create(healthPotion_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCHealthPotionIcon);
pobFrame = CCSpriteFrame::create(physicalPotion_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCPhysicalPotionIcon);
/* fireball */
pobFrame = CCSpriteFrame::create(fireballTrapWide_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCFireballWideIcon);
pobFrame = CCSpriteFrame::create(fireballTrapDamage_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCFireballDamageIcon);
/* curse */
pobFrame = CCSpriteFrame::create(curseTrapWide_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCCurseWideIcon);
pobFrame = CCSpriteFrame::create(curseTrapDamage_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCCurseDamageIcon);
/* paralysis */
pobFrame = CCSpriteFrame::create(paralysisTrapWide_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCParalysisWideIcon);
pobFrame = CCSpriteFrame::create(paralysisTrapDamage_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCParalysisDamageIcon);
/* fog */
pobFrame = CCSpriteFrame::create(fogTrapWide_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCFogWideIcon);
pobFrame = CCSpriteFrame::create(fogTrapDamage_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCFogDamageIcon);
/* flash */
pobFrame = CCSpriteFrame::create(flashTrapWide_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCFlashWideIcon);
pobFrame = CCSpriteFrame::create(flashTrapDamage_->item->getIcon()->getCString(),
iconRect);
cache->addSpriteFrame(pobFrame, kMCFlashDamageIcon);
__icon_loaded = true;
}
示例5: init
// on "init" you need to initialize your instance
bool GuiScroll::init()
{
int i;
std::string file_name;
CCSize visibleSize;
CCSprite* pPoint;
CCSprite* pSprite;
CCSpriteFrameCache* pCache;
CCLayer* pLayer;
bool bRet = false;
char pngstr[64] = {0};
//ratio is special for ios
float ratio = CCDirector::sharedDirector()->getContentScaleFactor();
m_nCurPage = 1;
if( CCLayer::init() )
{
visibleSize = CCDirector::sharedDirector()->getVisibleSize();
pLayer = CCLayer::create();
for (i=1; i<=3; i++)
{
sprintf(pngstr,"bgscroll.png");
file_name = (GetBaseAppPath()+"interface/").c_str();
file_name += pngstr;
pSprite = CCSprite::create(file_name.c_str());
pSprite->setPosition(ccp( ((float)i - 0.5f)*visibleSize.width, visibleSize.height/2.0f));
pLayer->addChild(pSprite);
}
m_pScrollView = CCScrollView::create(CCSizeMake(visibleSize.width*ratio, visibleSize.height*ratio), pLayer);
m_pScrollView->retain();
m_pScrollView->setContentOffset(CCPointZero);
m_pScrollView->setTouchEnabled(false);
m_pScrollView->setDelegate(this);
m_pScrollView->setDirection(kCCScrollViewDirectionHorizontal);
this->addChild(m_pScrollView,0);
pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
pCache->addSpriteFrame(CCSpriteFrame::create((GetBaseAppPath()+"interface/button_normal.png").c_str(),CCRectMake(0, 0, 32/ratio, 32/ratio)),"button_normal.png");
pCache->addSpriteFrame(CCSpriteFrame::create((GetBaseAppPath()+"interface/button_selected.png").c_str(),CCRectMake(0, 0, 32/ratio, 32/ratio)),"button_selected.png");
for (i=1; i<=3; i++)
{
pPoint = CCSprite::createWithSpriteFrameName("button_normal.png");
pPoint->setPosition(ccp( (visibleSize.width/2 - pPoint->getContentSize().width)+ pPoint->getContentSize().width * (i-1), 30));
pPoint->setTag(i);
this->addChild(pPoint,1);
}
pPoint = (CCSprite *)this->getChildByTag(1);
pPoint->setDisplayFrame(pCache->spriteFrameByName("button_selected.png"));
bRet = true;
}
return bRet;
}