Пример #1
0
cocos2d::FiniteTimeAction* cce::CCEChannel::getBezierActions(){
	int frameCount = this->keyframes.size();
		ccBezierConfig bezierCon;

	int startIndex,endIndex;
	ActionMoveFrame *lastFrame;
    for (int i = 0; i < frameCount; i++) {
		ActionMoveFrame *frame = (ActionMoveFrame *)this->keyframes.at(i);
		if(i==0){
			startIndex=frame->getFrameIndex();
			bezierCon.controlPoint_1=frame->getPosition();
		}else if(i==1){
			bezierCon.controlPoint_2=frame->getPosition();
		}else{
			endIndex=frame->getFrameIndex();
			bezierCon.endPosition =frame->getPosition();
			lastFrame=frame;
		}
	}

	float duration = (endIndex-startIndex) * getUnitTime();
	cocos2d::FiniteTimeAction *action=NULL;
	if(type=="BezierTo"){
		action=(CCBezierTo::create(duration, bezierCon));
	}else if(type=="BezierBy"){
		action=(CCBezierTo::create(duration, bezierCon));
	}
	if(startIndex>0){
		action = CCSequence::create(CCDelayTime::create(startIndex*getUnitTime()),action,nullptr);
	}
	
	return lastFrame->getEasingAction(action);
}
Пример #2
0
cocos2d::FiniteTimeAction* cce::CCEChannel::getSplineActions(){
	int frameCount = this->keyframes.size();
	if(frameCount==0){
		return NULL;
	}
	CCPointArray * array = CCPointArray::create(frameCount); 
	int startIndex,endIndex;
	ActionMoveFrame *lastFrame;
	for (int i = 0; i < frameCount; i++) {
		ActionMoveFrame *frame = (ActionMoveFrame *)this->keyframes.at(i);
		array->addControlPoint(frame->getPosition());
		if(i==0){
			startIndex = frame->getFrameIndex();
		}
		if(i==(frameCount-1)){
			endIndex=frame->getFrameIndex();
			lastFrame=frame;
		}
	}
	 

	float duration = (endIndex-startIndex) * getUnitTime();
	cocos2d::FiniteTimeAction *action=NULL;
	if(type=="SplineTo"){
		action= CCCardinalSplineTo::create(duration, array,0);
	}else if(type=="SplineBy"){
		action=CCCardinalSplineBy::create(duration, array,0);
	}
	if(startIndex>0){
		action = CCSequence::create(CCDelayTime::create(startIndex*getUnitTime()),action,nullptr);
	}
	return lastFrame->getEasingAction(action);
}
Пример #3
0
cocos2d::FiniteTimeAction* cce::CCEChannel::getSpriteActions(){
	int frameCount = this->keyframes.size();
	Vector<SpriteFrame *> cSpriteFrames;
	int startIndex=0;
	for (int i = 0; i < frameCount; i++) {
		SpriteNodeFrame *frame = (SpriteNodeFrame*)keyframes.at(i);
		SpriteFrame *spriteFrame = frame->getSpriteFrame();
		if(spriteFrame!=NULL){
			//log("pushBack %p",spriteFrame);
			cSpriteFrames.pushBack(spriteFrame);
		}
		if(i==0){
			startIndex = frame->getFrameIndex();
		}
	}

	//log("add sprite %f,%d",getUnitTime(),startIndex);
	if(startIndex<0){
		startIndex=0;
	}
	//log("add sprite %f,%d",getUnitTime(),startIndex);
	if(startIndex>0){
		return CCSequence::create(CCDelayTime::create(startIndex*getUnitTime()),Animate::create(Animation::createWithSpriteFrames(cSpriteFrames, getUnitTime(),1)),nullptr);
	}else{
		return Animate::create(Animation::createWithSpriteFrames(cSpriteFrames, getUnitTime(),1));
	}
}
Пример #4
0
bool ActionNode::updateActionToTimeLine(float fTime)
{
	bool bFindFrame = false;

	ActionFrame* srcFrame = nullptr;
	//	ActionFrame* destFrame = nullptr;

	for (int n = 0; n < _frameArrayNum; n++)
	{
		auto cArray = _frameArray.at(n);
		if (cArray->empty())
		{
			continue;
		}
		ssize_t frameCount = cArray->size();
		for (int i = 0; i < frameCount; i++)
		{
			auto frame = cArray->at(i);

			if (frame->getFrameIndex()*getUnitTime() == fTime)
			{
				this->easingToFrame(1.0f,1.0f,nullptr,frame);
				bFindFrame = true;
				break;
			}
			else if (frame->getFrameIndex()*getUnitTime() > fTime)
			{
				if (i == 0)
				{
					this->easingToFrame(1.0f,1.0f,nullptr,frame);
					bFindFrame = false;
				}
				else
				{
					srcFrame = cArray->at(i-1);
					float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex())*getUnitTime();
					float delaytime = fTime - srcFrame->getFrameIndex()*getUnitTime();
					this->easingToFrame(duration,1.0f,nullptr,srcFrame);
					//float easingTime = ActionFrameEasing::bounceTime(delaytime);
					this->easingToFrame(duration,delaytime/duration,srcFrame,frame);
					bFindFrame = true;
				}
				break;
			}
		}
	}
	return bFindFrame;
}
Пример #5
0
bool ActionNode::updateActionToTimeLine(float fTime)
{
	bool bFindFrame = false;

	ActionFrame* srcFrame = NULL;
	ActionFrame* destFrame = NULL;

	for (int n = 0; n < _frameArrayNum; n++)
	{
		Array* cArray = (Array*)(_frameArray->getObjectAtIndex(n));
		if (cArray == NULL)
		{
			continue;
		}
		int frameCount = cArray->count();
		for (int i = 0; i < frameCount; i++)
		{
			ActionFrame* frame = (ActionFrame*)(cArray->getObjectAtIndex(i));

			if (frame->getFrameIndex()*getUnitTime() == fTime)
			{
				this->easingToFrame(1.0f,1.0f,frame);
				bFindFrame = true;
				break;
			}
			else if (frame->getFrameIndex()*getUnitTime() > fTime)
			{
				if (i == 0)
				{
					this->easingToFrame(1.0f,1.0f,frame);
					bFindFrame = false;
				}
				else
				{
					srcFrame = (ActionFrame*)(cArray->getObjectAtIndex(i-1));
					float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex())*getUnitTime();
					float delaytime = fTime - srcFrame->getFrameIndex()*getUnitTime();
					this->easingToFrame(duration,1.0f,srcFrame);
					//float easingTime = ActionFrameEasing::bounceTime(delaytime);
					this->easingToFrame(duration,delaytime/duration,frame);
					bFindFrame = true;
				}
				break;
			}
		}
	}
	return bFindFrame;
}
Пример #6
0
cocos2d::FiniteTimeAction* cce::CCEChannel::getNormalActions(){
		
		int frameCount = this->keyframes.size();

		Vector<FiniteTimeAction *> cSequenceArray;

        for (int i = 0; i < frameCount; i++) {
            auto frame = this->keyframes.at(i);
            if (i == 0) {
                float duration = (frame->getFrameIndex()) * getUnitTime();
                FiniteTimeAction *cAction = frame->getAction(type,duration,NULL);
				if (cAction != nullptr){
                    cSequenceArray.pushBack((cAction));
				}else{
					log("Invalid key from %s ",type.c_str());
				}
            }
            else {
                auto srcFrame = this->keyframes.at(i - 1);
                float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex()) * getUnitTime();
                FiniteTimeAction *cAction = frame->getAction(type,duration,srcFrame);
				if (cAction != nullptr){
                    cSequenceArray.pushBack((cAction));
				}else{
					log("Invalid key from %s ",type.c_str());
				}
            }
        }

		cSequenceArray.pushBack(ChannelEndAction::create(this));
		log("cSequenceArray action size %d",cSequenceArray.size());
        return  Sequence::create(cSequenceArray);
}
Пример #7
0
CCSpawn * ActionNode::refreshActionProperty()
{
	if ( m_Object == NULL )
	{
		return NULL;
	}
	CCArray* cSpawnArray = CCArray::create();
	for (int n = 0; n < frameArrayNum; n++)
	{
		CCArray* cArray = (CCArray*)(m_FrameArray->objectAtIndex(n));
		if (cArray == NULL || cArray->count() <= 0)
		{
			continue;
		}

		CCArray* cSequenceArray = CCArray::create();
		int frameCount = cArray->count();
		for (int i = 0; i < frameCount; i++)
		{
			ActionFrame* frame = (ActionFrame*)(cArray->objectAtIndex(i));
			if (i == 0)
			{
				CCAction* cAction = frame->getAction(0);
				cSequenceArray->addObject(cAction);
			}
			else
			{
				ActionFrame* srcFrame = (ActionFrame*)(cArray->objectAtIndex(i-1));
				float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex()) * getUnitTime();
				CCAction* cAction = frame->getAction(duration,srcFrame);
				cSequenceArray->addObject(cAction);
			}
		}
		CCSequence* cSequence = CCSequence::create(cSequenceArray);
		if (cSequence != NULL)
		{
			cSpawnArray->addObject(cSequence);
		}
	}

	if (m_action == NULL)
	{
		CC_SAFE_RELEASE_NULL(m_actionSpawn);
	}
	else
	{
		CC_SAFE_RELEASE_NULL(m_action);
	}

	m_actionSpawn = CCSpawn::create(cSpawnArray);
	CC_SAFE_RETAIN(m_actionSpawn);
	return m_actionSpawn;
}
Пример #8
0
Spawn * ActionNode::refreshActionProperty()
{
	if ( _object == nullptr )
	{
		return nullptr;
	}
	Vector<FiniteTimeAction*> cSpawnArray;

	for (int n = 0; n < _frameArrayNum; n++)
	{
		auto cArray = _frameArray.at(n);
		if (cArray->size() <= 0)
		{
			continue;
		}

		Vector<FiniteTimeAction*> cSequenceArray;
		auto frameCount = cArray->size();
		for (int i = 0; i < frameCount; i++)
		{
			auto frame = cArray->at(i);
			if (i == 0)
			{
			}
			else
			{
				auto srcFrame = cArray->at(i-1);
				float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex()) * getUnitTime();
				Action* cAction = frame->getAction(duration);
				if(cAction != nullptr)
					cSequenceArray.pushBack(static_cast<FiniteTimeAction*>(cAction));
			}
		}
		Sequence* cSequence = Sequence::create(cSequenceArray);
		if (cSequence != nullptr)
		{
			cSpawnArray.pushBack(cSequence);
		}
	}

	if (_action == nullptr)
	{
		CC_SAFE_RELEASE_NULL(_actionSpawn);
	}
	else
	{
		CC_SAFE_RELEASE_NULL(_action);
	}

	_actionSpawn = Spawn::create(cSpawnArray);
	CC_SAFE_RETAIN(_actionSpawn);
	return _actionSpawn;
}
Пример #9
0
void ActionObject::initWithDictionary(JsonDictionary *dic,Object* root)
{
    setName(DICTOOL->getStringValue_json(dic, "name"));
    setLoop(DICTOOL->getBooleanValue_json(dic, "loop"));
	setUnitTime(DICTOOL->getFloatValue_json(dic, "unittime"));
    int actionNodeCount = DICTOOL->getArrayCount_json(dic, "actionnodelist");
    for (int i=0; i<actionNodeCount; i++) {
        ActionNode* actionNode = new ActionNode();
		actionNode->autorelease();
        JsonDictionary* actionNodeDic = DICTOOL->getDictionaryFromArray_json(dic, "actionnodelist", i);
        actionNode->initWithDictionary(actionNodeDic,root);
		actionNode->setUnitTime(getUnitTime());
        _actionNodeList->addObject(actionNode);
		CC_SAFE_DELETE(actionNodeDic);
    }
}
Пример #10
0
void ActionObject::initWithBinary(CocoLoader *cocoLoader,
                                  stExpCocoNode *cocoNode,
                                  cocos2d::Ref *root)
{
    stExpCocoNode *stChildNode = cocoNode->GetChildArray(cocoLoader);
    stExpCocoNode *actionNodeList = nullptr;
    int count = cocoNode->GetChildNum();
    for (int i = 0; i < count; ++i) {
        std::string key = stChildNode[i].GetName(cocoLoader);
        std::string value = stChildNode[i].GetValue(cocoLoader);
        if (key == "name") {
            setName(value.c_str());
        }else if (key == "loop"){
            setLoop(valueToBool(value));
        }else if(key == "unittime"){
            setUnitTime(valueToFloat(value));
        }else if (key == "actionnodelist"){
            actionNodeList = &stChildNode[i];
        }
    }
    
    if(nullptr != actionNodeList)
    {
        int actionNodeCount = actionNodeList->GetChildNum();
        stExpCocoNode *actionNodeArray = actionNodeList->GetChildArray(cocoLoader);
        int maxLength = 0;
        for (int i=0; i<actionNodeCount; i++) {
            ActionNode* actionNode = new ActionNode();
            actionNode->autorelease();
            
            actionNode->initWithBinary(cocoLoader, &actionNodeArray[i] , root);
            
            actionNode->setUnitTime(getUnitTime());
            
            _actionNodeList.pushBack(actionNode);
            
            int length = actionNode->getLastFrameIndex() - actionNode->getFirstFrameIndex();
            if(length > maxLength)
                maxLength = length;
        }
        
        
        _fTotalTime = maxLength* _fUnitTime;
    }
}
Пример #11
0
void ActionObject::initWithDictionary(const rapidjson::Value& dic, Ref* root)
{
    setName(DICTOOL->getStringValue_json(dic, "name"));
    setLoop(DICTOOL->getBooleanValue_json(dic, "loop"));
    setUnitTime(DICTOOL->getFloatValue_json(dic, "unittime"));
    int actionNodeCount = DICTOOL->getArrayCount_json(dic, "actionnodelist");
    int maxLength = 0;
    for (int i=0; i<actionNodeCount; i++) {
        ActionNode* actionNode = new ActionNode();
        actionNode->autorelease();
        const rapidjson::Value& actionNodeDic = DICTOOL->getDictionaryFromArray_json(dic, "actionnodelist", i);
        actionNode->initWithDictionary(actionNodeDic,root);
        actionNode->setUnitTime(getUnitTime());
        _actionNodeList.pushBack(actionNode);
        
        int length = actionNode->getLastFrameIndex() - actionNode->getFirstFrameIndex();
        if(length > maxLength)
            maxLength = length;
    }
    _fTotalTime = maxLength*_fUnitTime;
}
Пример #12
0
Spawn * ActionNode::refreshActionProperty()
{
    if ( _object == nullptr )
    {
        return nullptr;
    }
    Vector<FiniteTimeAction*> cSpawnArray;

    for (int n = 0; n < _frameArrayNum; n++)
    {
        auto cArray = _frameArray.at(n);
        if (cArray->size() <= 0)
        {
            continue;
        }

        Vector<FiniteTimeAction*> cSequenceArray;
        auto frameCount = cArray->size();
		if(frameCount > 1)
 		{ 
 			for (int i = 0; i < frameCount; i++)
 			{
 				auto frame = cArray->at(i);
 				if (i == 0)
 				{
// #11173 Fixed every node of UI animation(json) is starting at frame 0.                     
//                  if (frame->getFrameIndex() > 0)
//				    {
//					    DelayTime* cDelayTime = DelayTime::create(frame->getFrameIndex() * getUnitTime());
//					    if (cDelayTime != nullptr)
//						    cSequenceArray.pushBack(static_cast<FiniteTimeAction*>(cDelayTime));
//				    }
 				}
 				else
 				{
 					auto srcFrame = cArray->at(i-1);
 					float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex()) * getUnitTime();
 					Action* cAction = frame->getAction(duration);
 					if(cAction != nullptr)
 					cSequenceArray.pushBack(static_cast<FiniteTimeAction*>(cAction));
 				}
 			}
 		}
 		else if (frameCount == 1)
 		{
 			auto frame = cArray->at(0);
 			float duration = 0.0f;
 			Action* cAction = frame->getAction(duration);
 			if (cAction != nullptr)
 				cSequenceArray.pushBack(static_cast<FiniteTimeAction*>(cAction));
 		}
 		Sequence* cSequence = Sequence::create(cSequenceArray);
 		if (cSequence != nullptr)
 		{
 			cSpawnArray.pushBack(cSequence);
 		}
    }

    if (_action == nullptr)
    {
    CC_SAFE_RELEASE_NULL(_actionSpawn);
    }
    else
    {
    CC_SAFE_RELEASE_NULL(_action);
    CC_SAFE_RELEASE_NULL(_actionSpawn);
    }

    _actionSpawn = Spawn::create(cSpawnArray);
    CC_SAFE_RETAIN(_actionSpawn);
    return _actionSpawn;
}