Esempio n. 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);
}
Esempio n. 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);
}