当前位置: 首页>>代码示例>>C++>>正文


C++ CCSpriteFrame::getTexture方法代码示例

本文整理汇总了C++中CCSpriteFrame::getTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteFrame::getTexture方法的具体用法?C++ CCSpriteFrame::getTexture怎么用?C++ CCSpriteFrame::getTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCSpriteFrame的用法示例。


在下文中一共展示了CCSpriteFrame::getTexture方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: playAnimation

 // Starts playing a given animation (or nothing if this animation is already playing)
 void CocosSpriteActorView::playAnimation(const std::string &name)
 {        
     if (name != _currentAnimation)
     {
         SpriteActorView::playAnimation(name);
     
         if (_currentAnimation != "")
         {
             // Sprite wasn't created yet. Create and set parameters
             if (!_ccSprite)
             {
                 _ccSprite = CCSprite::spriteWithSpriteFrame(((CocosAnimation *)_animations[_currentAnimation].get())->getFirstFrame());    
                 if (_ccSprite)
                 {
                     setPosition(getPosition());
                     setAngle(getAngle());
                     setScale(getScale());
                     setZOrder(getZOrder());
                     setVisible(isVisible());
                     setAlpha(getAlpha());
                 }
             }
             
             // The sprite was created, change texture
             if (_ccSprite)
             {
                 bool isAnimation = _animations[_currentAnimation]->getFrameCount() > 1;
                 
                 CCSpriteFrame *frame = ((CocosAnimation *)_animations[_currentAnimation].get())->getFirstFrame();
                 _ccSprite->setTexture(frame->getTexture());
                 CCRect frameRect = frame->getRectInPixels();
                 if (isAnimation)
                 {
                     frameRect.origin = frame->getOffsetInPixels();
                 }
                 _ccSprite->setTextureRect(frameRect);
                 _ccSprite->setDisplayFrame(frame);
                 
                 // If this animation contains more than one frame, play the animation
                 if (isAnimation)
                 {
                     _ccSprite->runAction(((CocosAnimation *)_animations[_currentAnimation].get())->getAnimationAction());
                 }
             }
             
         }
     }
 }
开发者ID:Avnerus,项目名称:ichigo,代码行数:49,代码来源:CocosSpriteActorView.cpp

示例2: getTexture

CCTexture2D* getTexture(std::string theImageFullPath, CCRect& theTextureRect){
	// try to load from sprite sheet
	std::string anImageFileName;
	int aLastSlashIndex = MAX((int)theImageFullPath.find_last_of('/'), (int)theImageFullPath.find_last_of('\\'));
	if (aLastSlashIndex != std::string::npos) {
		anImageFileName = theImageFullPath.substr(aLastSlashIndex + 1);
	} else {
		anImageFileName = theImageFullPath;
	}
	CCSpriteFrame *aSpriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(anImageFileName.c_str());
	if (aSpriteFrame) {
		theTextureRect = aSpriteFrame->getRect();
		return aSpriteFrame->getTexture();
	}
	
	CCTexture2D* aTexture = CCTextureCache::sharedTextureCache()->addImage(theImageFullPath.c_str());
	theTextureRect.origin = CCPointZero;
	theTextureRect.size = aTexture->getContentSize();
	return aTexture;
}
开发者ID:xiangry,项目名称:cocos2dx-classical,代码行数:20,代码来源:CCSuperAnim.cpp

示例3: setID

 // Sets the tile's texture according to the given ID. If this is the first time the tile is set, also create the cocos sprite
 void CocosTile::setID(std::string tileID)
 {
     Tile::setID(tileID);
     
     // Load texture according to given ID
     CCSpriteFrame *frame = loadSpriteFrame(_tileName + "_" + tileID + "." + _tileExt);
     if (frame)
     {
         // Set texture to sprite
         if (_sprite)
         {
             _sprite->setTexture(frame->getTexture());
             _sprite->setTextureRect(frame->getRect());
         }
         else
         {
             // Sprite not created yet, create it using this texture
             _sprite = CCSprite::spriteWithSpriteFrame(frame);
         }
     }
 }
开发者ID:Avnerus,项目名称:ichigo,代码行数:22,代码来源:CocosTile.cpp

示例4: removeSpriteFramesFromTexture

void CCSpriteFrameCache::removeSpriteFramesFromTexture(CCTexture2D* texture)
{
	vector<string> keysToRemove;

	m_pSpriteFrames->begin();
	std::string key = "";
	CCDictionary<std::string, CCObject*> *frameDict = NULL;
	while( (frameDict = (CCDictionary<std::string, CCObject*>*)m_pSpriteFrames->next(&key)) )
	{
		CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(key);
		if (frame && (frame->getTexture() == texture))
		{
			keysToRemove.push_back(key);
		}
	}
	m_pSpriteFrames->end();

	vector<string>::iterator iter;
	for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
	{
		m_pSpriteFrames->removeObjectForKey(*iter);
	}
}
开发者ID:9miao,项目名称:cocos2dx-win8,代码行数:23,代码来源:CCSpriteFrameCache.cpp

示例5: setTextureWithFrames

//the frames should have the same size in texture so shouldn't trim the frame
//I wish this limit will be removed in next moment
void CCParticleSystemFrameQuad::setTextureWithFrames(CCTexture2D* texture, CCArray* frames)
{
    // Only update the texture if is different from the current one
    if( !m_pTexture || texture->getName() != m_pTexture->getName() )
    {
        CCParticleSystem::setTexture(texture);
    }

	clearFrameSetting();
	unsigned int totalFrames = frames->count();
	m_pFrameQuads = new float *[totalFrames];
	for(unsigned int i=0; i<totalFrames;i++){
		CCSpriteFrame *frame = dynamic_cast<CCSpriteFrame*>(frames->objectAtIndex(i));
		if(frame==NULL || frame->getTexture()->getName()!= m_pTexture->getName())
			continue;
		
		CCRect rect = frame->getRect();

		float* m_sQuad = new float[4];
		m_pFrameQuads[m_uTotalFrames] = m_sQuad;
		m_uTotalFrames++;

		float atlasWidth = (float)m_pTexture->getPixelsWide();
		float atlasHeight = (float)m_pTexture->getPixelsHigh();

		float left, right, top, bottom;

		if (frame->isRotated())
		{
	#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
			left    = (2*rect.origin.x+1)/(2*atlasWidth);
			right    = left+(rect.size.height*2-2)/(2*atlasWidth);
			top        = (2*rect.origin.y+1)/(2*atlasHeight);
			bottom    = top+(rect.size.width*2-2)/(2*atlasHeight);
	#else
			left    = rect.origin.x/atlasWidth;
			right    = (rect.origin.x+rect.size.height) / atlasWidth;
			top        = rect.origin.y/atlasHeight;
			bottom    = (rect.origin.y+rect.size.width) / atlasHeight;
	#endif // CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
		}
		else
		{
	#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
			left    = (2*rect.origin.x+1)/(2*atlasWidth);
			right    = left + (rect.size.width*2-2)/(2*atlasWidth);
			top        = (2*rect.origin.y+1)/(2*atlasHeight);
			bottom    = top + (rect.size.height*2-2)/(2*atlasHeight);
	#else
			left    = rect.origin.x/atlasWidth;
			right    = (rect.origin.x + rect.size.width) / atlasWidth;
			top        = rect.origin.y/atlasHeight;
			bottom    = (rect.origin.y + rect.size.height) / atlasHeight;
	#endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
		}
		m_sQuad[0] = left;
		m_sQuad[1] = right;
		m_sQuad[2] = top;
		m_sQuad[3] = bottom;
	}

    GLfloat wide = (GLfloat)m_pTexture->getPixelsWide();
    GLfloat high = (GLfloat)m_pTexture->getPixelsHigh();

    ccV3F_C4B_T2F_Quad *quads = NULL;
    unsigned int start = 0, end = 0;
    if (m_pBatchNode)
    {
        quads = m_pBatchNode->getTextureAtlas()->getQuads();
        start = m_uAtlasIndex;
        end = m_uAtlasIndex + m_uTotalParticles;
    }
    else
    {
        quads = m_pQuads;
        start = 0;
        end = m_uTotalParticles;
    }

    for(unsigned int i=start; i<end; i++) 
    {
		int fid = rand()%m_uTotalFrames;
		float* m_sQuad = m_pFrameQuads[fid];
        // bottom-left vertex:
        quads[i].bl.texCoords.u = m_sQuad[0];
        quads[i].bl.texCoords.v = m_sQuad[3];
        // bottom-right vertex:
        quads[i].br.texCoords.u = m_sQuad[1];
        quads[i].br.texCoords.v = m_sQuad[3];
        // top-left vertex:
        quads[i].tl.texCoords.u = m_sQuad[0];
        quads[i].tl.texCoords.v = m_sQuad[2];
        // top-right vertex:
        quads[i].tr.texCoords.u = m_sQuad[1];
        quads[i].tr.texCoords.v = m_sQuad[2];
    }
}
开发者ID:liyonghelpme,项目名称:iosdifferentbranchcode,代码行数:99,代码来源:CCParticleSystemFrameQuad.cpp


注:本文中的CCSpriteFrame::getTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。