CCFiniteTimeAction* AppConfig::getActionWithAnimate(const char* animateName, float duration)
{
	CCAnimation* pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(animateName);
	if(pAnimation){
		CCAnimate* pAnimate = CCAnimate::create(pAnimation);
		pAnimate->setDuration(duration);
		pAnimation->setRestoreOriginalFrame(false);
		return pAnimate;
	}
	return NULL;
}
Example #2
0
int ShieldedObject::playShieldAnimation(int damage, int angle)
{
	CCAnimate* animate;
	map<int,cocos2d::CCAnimation*>::iterator it = getShieldAnimations()->find(0);
	if (it == getShieldAnimations()->end()) 
	{
		return 0;
	}
	else 
	{
		animate = CCAnimate::create(it->second);
	}
	animate->setDuration(0.13f);
	//runAction(animate);
	node->setAnchorPoint(ccp(0.5, 0.5));
	node->setRotation(angle);
	node->runAction(animate);
	return 1;
}
Example #3
0
void Animal::runActionWithMotion(MOTION motion)
{
    CCAnimation *animation	= CCAnimation::create();
	animation->setDelayPerUnit(0.1f);
    
    for( int iFrame = 0; iFrame < SPRITE_FRAME; iFrame++ )
	{
        CCTexture2D *pTexture	= animates[motion][iFrame];
        CCSize		sizeTexture = pTexture->getContentSize();
		animation->addSpriteFrameWithTexture(pTexture, CCRectMake(0, 0, sizeTexture.width, sizeTexture.height));
	}
    
	CCAnimate			*animate	= CCAnimate::create(animation);
    
    CCFiniteTimeAction	*action;
	CCPoint				direction;

	animate->setDuration(duration[motion]);

	switch(motion)
	{
	case WALK_LEFT:			
	case RUN_LEFT:			
		direction = ccp(-1.f, -1.f);	break;
	case WALK_RIGHT:		
	case RUN_RIGHT:			
		direction = ccp( 1.f, -1.f);	break;
	case WALK_BACK_LEFT:
	case RUN_BACK_LEFT:
		direction = ccp(-1.f,  1.f);	break;
	case WALK_BACK_RIGHT:
	case RUN_BACK_RIGHT:
		direction = ccp( 1.f,  1.f);	break;
	}

	switch(motion)
	{
	case WALK_LEFT:
	case WALK_RIGHT:
	case WALK_BACK_LEFT:
	case WALK_BACK_RIGHT:
		{
			CCPoint walk = ccp(direction.x*walk_scale.x, direction.y*walk_scale.y);
			action = CCSequence::actions(	
				CCSpawn::actions(CCMoveBy::create(duration[motion], walk), animate, NULL), 
				CCCallFuncN::actionWithTarget(this, callfuncN_selector(Animal::finishChk)), NULL);
		}
		break;
	case RUN_LEFT:
	case RUN_RIGHT:
	case RUN_BACK_LEFT:
	case RUN_BACK_RIGHT:
		{
			CCPoint run = ccp(direction.x*run_scale.x, direction.y*run_scale.y);
			action = CCSequence::actions(	
				CCSpawn::actions(CCMoveBy::create(duration[motion], run), animate, NULL), 
				CCCallFuncN::actionWithTarget(this, callfuncN_selector(Animal::finishChk)), NULL);
		}
		break;
	case STAND:
	case SIT:
	case SLEEP:
	case EAT:
	case POOP:
	case SICK:
	case FUN_SWING:
	case FUN_RUNNING:
	case FUN_ROPE:
		action = CCSequence::actions(	
			animate, 
			CCCallFuncN::actionWithTarget(this, callfuncN_selector(Animal::finishChk)), NULL);
		break;
	}
	motionState.name = motion;
	pBody->runAction(action);
}