}

CCAction* HelloWorld::createAction(int begin,int end,char* cacheActionName,CCPoint point){
	CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();
	CCArray *array = CCArray::createWithCapacity(end-begin);

	char name[20];
	for(int i = begin ;i<end;i++){
		sprintf(name,"A1_%d.png",i);
		CCSpriteFrame* frame =cache->spriteFrameByName(name);
		array->addObject(frame);
	}

	CCAnimation *plistAnimation = CCAnimation::createWithSpriteFrames(array,0.2f);
	CCAnimationCache::sharedAnimationCache()->addAnimation(plistAnimation, cacheActionName);

	array->removeAllObjects();

	CCAnimation *animation = animCache->animationByName(cacheActionName);
	animation->setRestoreOriginalFrame(true);
	CCAnimate *ani=CCAnimate::create(animation);
	CCActionInterval* plistSeq=(CCActionInterval*)(CCSequence::create(ani,
		CCFlipX::create(point.x>0? true:false),
		ani->copy()->autorelease(),
		NULL
	));
void SheetAnimations_LoadAnimationTest::executeTestCodeAtPosition(CCPoint p)
{
    
    GHSprite * sprite = GHSprite::createWithSpriteFrameName("number_0.png");//the name of one of the sprite in the sheet plist
    
    if(batchNodeParent != NULL){//if we use batch nodes we must add the sprite to its batch parent
        batchNodeParent->addChild(sprite);
    }
    else{//if we dont use batch nodes then we must add the sprite to a normal node - e.g the layer or another node
        this->addChild(sprite);
    }
    sprite->setPosition(p);
    
    
    CCAnimationCache *cache = CCAnimationCache::sharedAnimationCache();
    CCAnimation *animation = cache->animationByName("NumbersAnim");//the name of the animation
    
    CCAnimate* action = CCAnimate::create(animation);
    sprite->runAction(action);
    
    
    //    [sprite runAction: [CCSequence actions: action, [action reverse], nil]];
    

    CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
                                                                  callfuncO_selector(SheetAnimations_LoadAnimationTest::animationFrameNotification),
                                                                  CCAnimationFrameDisplayedNotification,
                                                                  NULL);
}
}

void HelloWorld::moveDone(){
	//
	sprite->stopAllActions();
	CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();


	CCAnimation *standAnimation = animCache->animationByName("stand");
		standAnimation->setRestoreOriginalFrame(true);
		CCAnimate *standAni=CCAnimate::create(standAnimation);
		CCActionInterval* s=(CCActionInterval*)(CCSequence::create(standAni,
			standAni->copy()->autorelease(),
			NULL
		));
		CCAction *frameAction=CCRepeatForever::create(s);

	
Esempio n. 4
0
void HelloWorld::MoveDone()
{
    PlayerIsIdle = true;
    m_pSprite->stopAllActions();
    CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();
    
    char name[20];
    sprintf(name,"stand%d",dirction);
	CCAnimation *standAnimation = animCache->animationByName(name);
    if (standAnimation==NULL)
    {
        CCArray * standArray= CCArray::createWithCapacity(1);
        char standName[20];
		int dir ;
        if (dirction == 6 )
        {    dir = 2;}
        else
        { dir = dirction;}
        
        for(int i=7;i<8;i++){
			sprintf(standName,
                    "walk_%d_%d.png",dir,i);
            
			CCSpriteFrame* frame =cache->spriteFrameByName(standName);
			standArray->addObject(frame);
		}
		standAnimation =CCAnimation::createWithSpriteFrames(standArray,0.2f);
		animCache->addAnimation(standAnimation, name);
		standArray->removeAllObjects();
        delete standArray;
    }
    standAnimation->setRestoreOriginalFrame(true);
    CCAnimate *standAni=CCAnimate::create(standAnimation);
    CCActionInterval* s=(CCActionInterval*)(CCSequence::create(standAni,
                                                               standAni->copy()->autorelease(),
                                                               NULL
                                                               ));
    CCAction *frameAction=CCRepeatForever::create(s);
    
	
	m_pSprite->setFlipX(dirction == 6);
	m_pSprite->runAction(frameAction);
}
//-------------------------------------------------------------------------
void CStarWidget::DoEffect(CCPoint&pos,string strEffectName,string strEffectFirstFarmeName)
{
	CCAnimationCache* pAnimeCache = CCAnimationCache::sharedAnimationCache();
	if (pAnimeCache == NULL)
	{
		return;
	}

	CCAnimation* pAnime = pAnimeCache->animationByName(strEffectName.c_str());
	if ( pAnime == NULL)
	{
		return;
	}

	CCAnimate * pAnimate = CCAnimate::create(pAnime);
	CCSprite* spTemp = CCSprite::createWithSpriteFrameName(strEffectFirstFarmeName.c_str());
	spTemp->setAnchorPoint(ccp(0.5,0.5));
	addChild(spTemp);
	spTemp->setPosition(pos);
	CCFiniteTimeAction* actions= CCSequence::create(pAnimate,  
		CCCallFuncN::create(this,callfuncN_selector(CStarWidget::OnEffectEnd)),NULL);
	spTemp->runAction(actions);
}
Esempio n. 6
0
void Recipe15::eat(float delta)
{
	CCSprite* player = (CCSprite*) this->getChildByTag(1);
	player->setTexture(CCTextureCache::sharedTextureCache()->addImage("monkey01.png"));

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	this->m_points += player->getPositionX()/(winSize.width/4) + 1;

	CCLabelTTF* label = (CCLabelTTF*)this->getChildByTag(11);

	CCString* points = CCString::createWithFormat("%d", this->m_points);

	label->setString(points->getCString());

	CCAnimationCache* cache = CCAnimationCache::sharedAnimationCache();
	cache->addAnimationsWithFile("animations.plist");

	CCAnimation* animation2 = cache->animationByName("bite");

	CCAnimate* action = CCAnimate::create(animation2);
	player->runAction(action);
}
Esempio n. 7
0
CCAnimation * CCNodeLoader::parsePropTypeAnimation(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
    CCString * animationFile = pCCBReader->readCachedString();
    CCString * animation = pCCBReader->readCachedString();
    
    CCAnimation * ccAnimation = NULL;
    
    // Support for stripping relative file paths, since ios doesn't currently
    // know what to do with them, since its pulling from bundle.
    // Eventually this should be handled by a client side asset manager
    // interface which figured out what resources to load.
    // TODO Does this problem exist in C++?
    animation = CCBReader::lastPathComponent(animation);
    animationFile = CCBReader::lastPathComponent(animationFile);
    
    if (animation != NULL && animation->compare("") != 0) 
    {
        CCAnimationCache * animationCache = CCAnimationCache::sharedAnimationCache();
        animationCache->addAnimationsWithFile(animationFile->getCString());
        
        ccAnimation = animationCache->animationByName(animation->getCString());
    }
    return ccAnimation;
}