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


C++ CCAnimation::retain方法代码示例

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


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

示例1:

std::map<int, cocos2d::CCAnimation*>* ShieldedObject::getShieldAnimations()
{
	if (shieldAnimations == NULL)
	{
		shieldAnimations = new map<int, cocos2d::CCAnimation*>;
		for (int i = 0; i < 1; i++)
		{
			CCAnimation *animation;
			animation = CCAnimation::create();
			animation->retain();
			animation->setDelayPerUnit(0.05f);
			animation->addSpriteFrameWithFileName("res/image/shield7.png");
			animation->addSpriteFrameWithFileName("res/image/shield6.png");
			animation->addSpriteFrameWithFileName("res/image/shield5.png");
			animation->addSpriteFrameWithFileName("res/image/shield4.png");
			animation->addSpriteFrameWithFileName("res/image/shield3.png");
			animation->addSpriteFrameWithFileName("res/image/shield2.png");
			animation->addSpriteFrameWithFileName("res/image/shield1.png");
			animation->addSpriteFrameWithFileName("res/image/shield.png");
			animation->addSpriteFrameWithFileName("res/image/shield.png");
			animation->addSpriteFrameWithFileName("res/image/shield.png");
			animation->addSpriteFrameWithFileName("res/image/shield1.png");
			animation->addSpriteFrameWithFileName("res/image/shield2.png");
			animation->addSpriteFrameWithFileName("res/image/shield3.png");
			animation->addSpriteFrameWithFileName("res/image/shield4.png");
			animation->addSpriteFrameWithFileName("res/image/shield5.png");
			animation->addSpriteFrameWithFileName("res/image/shield6.png");
			animation->addSpriteFrameWithFileName("res/image/shield7.png");
			animation->addSpriteFrameWithFileName("res/image/shield0.png");
			(*shieldAnimations)[i] = animation;
		}
	}
	return shieldAnimations;
}
开发者ID:wi-secret,项目名称:TestGame,代码行数:34,代码来源:ShieldedObject.cpp

示例2: _LoadRes

//-------------------------------------------------------------------------
// 加载资源
void FKAnimateExRes::_LoadRes( const char* szResName )
{
	string strPathName = CCFileUtils::sharedFileUtils()->fullPathForFilename( szResName );

	// 加载Plist
	vector<string>	vecPlists = m_SaxDelegator.m_vecPlists;
	for( unsigned int i = 0; i < vecPlists.size(); ++i )
	{
		string strPlistPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(
			vecPlists[i].c_str(), strPathName.c_str() );
		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( strPlistPath.c_str() );
	}

	// 加载Animate
	vector<SAnimate> vecAnimates = m_SaxDelegator.m_vecAnimates;
	CCArray* pSpriteFramesArray = CCArray::create();
	for( unsigned int i = 0; i < vecAnimates.size(); ++i )
	{
		SAnimate tagAnimate = vecAnimates[i];
		vector<string>	vecSpriteFrames = tagAnimate.m_vecSpriteFrame;

		for( unsigned int j = 0; j < vecSpriteFrames.size(); ++j )
		{
			CCSpriteFrame* pSpriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(vecSpriteFrames[j].c_str());
			if( pSpriteFrame != NULL )
			{
				pSpriteFramesArray->addObject( pSpriteFrame );
			}
		}

		CCAnimation* pAnimation = CCAnimation::createWithSpriteFrames( pSpriteFramesArray, tagAnimate.m_fDelay );

		SAnimationInfo tagInfo;
		tagInfo.m_pAnimation	= pAnimation;
		tagInfo.m_bIsFlipX		= tagAnimate.m_bIsFlipX;
		tagInfo.m_bIsFlipY		= tagAnimate.m_bIsFlipY;
		m_mapAnimation[tagAnimate.m_strName] = tagInfo;

		pAnimation->retain();
		pSpriteFramesArray->removeAllObjects();
		m_setAnimationName.insert( tagAnimate.m_strName );
	}

	// 保存Animate
	for( unsigned int i = 0; i < vecAnimates.size(); ++i )
	{
		SAnimate tagAnimate = vecAnimates[i];
		m_mapAnimateNameToAnimate[tagAnimate.m_strName] = tagAnimate;
	}
	// 保存Plist
	m_mapXMLPathToPlists[szResName] = vecPlists;

	// 加载回调函数
	_LoadCallback( szResName );

	m_bIsVaild = true;
}
开发者ID:duzhi5368,项目名称:FKCocos2dxWrapper_2.x,代码行数:59,代码来源:FKAnimateExRes.cpp

示例3: loadFile

void MAnimation::loadFile(const std::string& fileName)
{
    tinyxml2::XMLDocument doc;
    //std::string s = CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName.c_str());
    //doc.LoadFile(s.c_str());
    doc.LoadFile(fileName.c_str());
    
    tinyxml2::XMLElement* root = doc.RootElement();
    if(std::strcmp(version.c_str(), root->FirstAttribute()->Value()) != 0)
    {
        CCAssert(0, "版本不匹配");
    }

    tinyxml2::XMLElement* animation;
    animation = root->FirstChildElement("animation");
    while(animation != NULL)
    {
        tinyxml2::XMLElement* ele = animation->FirstChildElement("animationName");
        std::string animationName = ele->GetText();
        
        //属性
        MAnimationProperty* property = new MAnimationProperty;
        float scale; float rotate;
        CCPoint position = CCPointZero;
        std::string strPosition = animation->FirstAttribute()->Value(); //position
        std::string::size_type pos = strPosition.find(",");
        std::string strX, strY;
        strX = strPosition.substr(0, pos);
        strY = strPosition.substr(pos + 1, strPosition.length());
        float x = std::atof(strX.c_str()), y = std::atof(strY.c_str());
        position.setPoint(x, y);
        animation->QueryFloatAttribute("scale", &scale);
        animation->QueryFloatAttribute("rotation", &rotate);
        property->positionX = x;
        property->positionY = y;
        property->scaleX = property->scaleY = scale;
        property->rotation = rotate;
        nameToAnimationProperty->insert(std::make_pair(animationName, property));
        
        int frameCount;
        ele = animation->FirstChildElement("frameCount");
        ele->QueryIntText(&frameCount);
        
        float delayPerUnit;
        ele = animation->FirstChildElement("delayPerUnit");
        ele->QueryFloatText(&delayPerUnit);
        
        bool restoreOriginFrame;
        ele = animation->FirstChildElement("restoreOriginFrame");
        ele->QueryBoolText(&restoreOriginFrame);
        
        int loops;
        ele = animation->FirstChildElement("loops");
        ele->QueryIntText(&loops);
        
        //创建CCAnimation
        CCArray* arr = CCArray::create();
        CCAnimation* ccanimation;
        ccanimation = CCAnimationCache::sharedAnimationCache()->animationByName(animationName.c_str());
        if(ccanimation == NULL)
        {
            std::string plistName = animationName;
            plistName += ".plist";
            CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
            cache->addSpriteFramesWithFile(plistName.c_str());
            char c[100];
            for(int i = 0; i < frameCount; ++i)
            {
                sprintf(c, "%s_%02d.png", animationName.c_str(), i);
                CCSpriteFrame* frame = cache->spriteFrameByName(c);
                arr->addObject(frame);
            }
            ccanimation = CCAnimation::createWithSpriteFrames(arr);
            ccanimation->setDelayPerUnit(delayPerUnit);
            ccanimation->setRestoreOriginalFrame(restoreOriginFrame);
            ccanimation->setLoops(loops);
            CCAnimationCache::sharedAnimationCache()->addAnimation(ccanimation, animationName.c_str()); //加入缓存
        }
        ccanimation->retain();
        nameToCCAnimation->insert(std::make_pair(animationName, ccanimation));
        
        animation = animation->NextSiblingElement("animation");
    }
    
}
开发者ID:xu561865,项目名称:demo_2,代码行数:85,代码来源:MAnimation.cpp

示例4: ccp

bool Level12::ccTouchBegan(cocos2d::CCTouch *touch, cocos2d::CCEvent *event)
{
    CCPoint touchLocation = touch->getLocationInView();
    touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
    if (spSun->boundingBox().containsPoint(touchLocation)) {
        spSun->stopAllActions();
        SimpleAudioEngine::sharedEngine()->stopAllEffects();
        SimpleAudioEngine::sharedEngine()->playEffect("sun.wav");
        spSun->runAction(CCRotateBy::create(1.0f, 360.f));
        return false;
    }
    if (spBall->boundingBox().containsPoint(touchLocation)) {
        spBall->stopAllActions();
        spBall->setPosition(ccp(getXForLession1(150), getYForLession1(393)));
        SimpleAudioEngine::sharedEngine()->stopAllEffects();
        SimpleAudioEngine::sharedEngine()->playEffect("ball.wav");
        spBallShadow->setVisible(false);
        spBall->runAction(CCSequence::create(CCJumpBy::create(0.6f, ccp(0, 0), 150*G_SCALEY, 1),CCJumpBy::create(0.4f, ccp(0, 0), 80*G_SCALEY, 1),CCJumpBy::create(0.2f, ccp(0, 0), 40*G_SCALEY, 1), CCCallFunc::create(this, callfunc_selector(Level12::showShadow)),NULL));
        return false;
    }
    
    if (spRock->boundingBox().containsPoint(touchLocation)) {
        spRock->stopAllActions();
        spRock->setPosition(ccp(getXForLession1(410), G_SHEIGHT/2));
        SimpleAudioEngine::sharedEngine()->stopAllEffects();
        SimpleAudioEngine::sharedEngine()->playEffect("rock.wav");
        spRockShadow->setVisible(false);
        spRock->runAction(CCSequence::create(CCJumpBy::create(1.f, ccp(0, 0), 150*G_SCALEY, 1),CCCallFunc::create(this, callfunc_selector(Level12::showShadow)), NULL));
        return false;
    }
    

    
    if (spGrass->boundingBox().containsPoint(touchLocation)) {
        spGrass->stopAllActions();
        SimpleAudioEngine::sharedEngine()->stopAllEffects();
        SimpleAudioEngine::sharedEngine()->playEffect("grass.wav");
        
        CCAnimation *animation = CCAnimation::create();
        animation->setDelayPerUnit(0.5f);
        
        for (int i = 0; i < 2; i ++) {
            CCTexture2D *txtr = CCTextureCache::sharedTextureCache()->addImage(CCString::createWithFormat("grass_%d.png", i+1)->getCString());
            CCSize size = txtr->getContentSize();
            CCRect rect = CCRectMake(0, 0, size.width, size.height);
            CCSpriteFrame *frame = CCSpriteFrame::createWithTexture(txtr, rect);
            animation->addSpriteFrame(frame);
        }
        animation->retain();
        
        spGrass->runAction(CCRepeat::create(CCAnimate::create(animation), 2));
        return false;
    }
    
    if (spHitBox->boundingBox().containsPoint(touchLocation)) {
        SimpleAudioEngine::sharedEngine()->stopAllEffects();
        
        SimpleAudioEngine::sharedEngine()->playEffect("water.wav");
    }
    
    return false;
}
开发者ID:Biswajit-MobileDeveloper,项目名称:StoryBook,代码行数:62,代码来源:Level12.cpp


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