Example #1
0
void ActionNode::initWithDictionary(const rapidjson::Value& dic,CCObject* root)
{
	setActionTag(DICTOOL->getIntValue_json(dic, "ActionTag"));
	int actionFrameCount = DICTOOL->getArrayCount_json(dic, "actionframelist");
	for (int i=0; i<actionFrameCount; i++) {

		const rapidjson::Value& actionFrameDic = DICTOOL->getDictionaryFromArray_json(dic, "actionframelist", i);
		int frameInex = DICTOOL->getIntValue_json(actionFrameDic,"frameid");

		bool existPosition = DICTOOL->checkObjectExist_json(actionFrameDic,"positionx");
		if (existPosition)
		{
			float positionX = DICTOOL->getFloatValue_json(actionFrameDic, "positionx");
			float positionY = DICTOOL->getFloatValue_json(actionFrameDic, "positiony");
			ActionMoveFrame* actionFrame = new ActionMoveFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setPosition(CCPointMake(positionX, positionY));
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeMove);
			cActionArray->addObject(actionFrame);
		}

		bool existScale = DICTOOL->checkObjectExist_json(actionFrameDic,"scalex");
		if (existScale)
		{
			float scaleX = DICTOOL->getFloatValue_json(actionFrameDic, "scalex");
			float scaleY = DICTOOL->getFloatValue_json(actionFrameDic, "scaley");
			ActionScaleFrame* actionFrame = new ActionScaleFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setScaleX(scaleX);
			actionFrame->setScaleY(scaleY);
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeScale);
			cActionArray->addObject(actionFrame);
		}

		bool existRotation = DICTOOL->checkObjectExist_json(actionFrameDic,"rotation");
		if (existRotation)
		{
			float rotation = DICTOOL->getFloatValue_json(actionFrameDic, "rotation");
			ActionRotationFrame* actionFrame = new ActionRotationFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setRotation(rotation);
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeRotate);
			cActionArray->addObject(actionFrame);
		}

		bool existOpacity = DICTOOL->checkObjectExist_json(actionFrameDic,"opacity");
		if (existOpacity)
		{
			int opacity = DICTOOL->getIntValue_json(actionFrameDic, "opacity");
			ActionFadeFrame* actionFrame = new ActionFadeFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setOpacity(opacity);
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeFade);
			cActionArray->addObject(actionFrame);
		}

		bool existColor = DICTOOL->checkObjectExist_json(actionFrameDic,"colorr");
		if (existColor)
		{
			int colorR = DICTOOL->getIntValue_json(actionFrameDic, "colorr");
			int colorG = DICTOOL->getIntValue_json(actionFrameDic, "colorg");
			int colorB = DICTOOL->getIntValue_json(actionFrameDic, "colorb");
			ActionTintFrame* actionFrame = new ActionTintFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setColor(ccc3(colorR,colorG,colorB));
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeTint);
			cActionArray->addObject(actionFrame);
		}

	}
	initActionNodeFromRoot(root);
}
Example #2
0
 void ActionNode::initWithBinary(CocoLoader *cocoLoader,
                                 stExpCocoNode *cocoNode,
                                 cocos2d::Ref *root)
 {
     
     stExpCocoNode *stChildNode = cocoNode;
     
     int actionNodeCount =  stChildNode->GetChildNum();
     stChildNode = stChildNode[0].GetChildArray(cocoLoader);
     stExpCocoNode *frameListNode = nullptr;
     for (int i = 0; i < actionNodeCount; ++i) {
         std::string key = stChildNode[i].GetName(cocoLoader);
         std::string value = stChildNode[i].GetValue(cocoLoader);
         if (key == "ActionTag") {
             setActionTag(valueToInt(value));
         }else if (key == "actionframelist"){
             frameListNode = &stChildNode[i];
         }
     }
     
     int actionFrameCount = frameListNode->GetChildNum();
     stExpCocoNode *stFrameChildNode = frameListNode->GetChildArray(cocoLoader);
     for (int i=0; i<actionFrameCount; i++) {
         
         int frameIndex;
         int frameTweenType;
         float positionX;
         float positionY;
         float scaleX;
         float scaleY;
         float rotation;
         int opacity;
         int colorR = -1;
         int colorG = -1;
         int colorB = -1;
         std::vector<float> frameTweenParameter;
         
         int framesCount = stFrameChildNode[i].GetChildNum();
         stExpCocoNode *innerFrameNode = stFrameChildNode[i].GetChildArray(cocoLoader);
         for (int j = 0; j < framesCount; j++) {
             std::string key = innerFrameNode[j].GetName(cocoLoader);
             std::string value = innerFrameNode[j].GetValue(cocoLoader);
             
             if (key == "frameid") {
                 frameIndex = valueToInt(value);
             }else if(key == "tweenType"){
                 frameTweenType = valueToInt(value);
             }else if (key == "tweenParameter"){
                 //  There are no tweenParameter args in the json file
                 int tweenParameterCount = innerFrameNode[j].GetChildNum();
                 stExpCocoNode *tweenParameterArray = innerFrameNode[j].GetChildArray(cocoLoader);
                 for (int k = 0; k < tweenParameterCount; ++k) {
                     std::string t_key = tweenParameterArray[j].GetName(cocoLoader);
                     std::string t_value = tweenParameterArray[j].GetValue(cocoLoader);
                     frameTweenParameter.push_back(valueToFloat(t_value));
                 }
             }else if (key == "positionx"){
                 positionX = valueToFloat(value);
             }else if (key == "positiony"){
                 positionY = valueToFloat(value);
                 ActionMoveFrame* actionFrame = new (std::nothrow) ActionMoveFrame();
                 actionFrame->autorelease();
                 actionFrame->setEasingType(frameTweenType);
                 actionFrame->setEasingParameter(frameTweenParameter);
                 actionFrame->setFrameIndex(frameIndex);
                 actionFrame->setPosition(Vec2(positionX, positionY));
                 auto cActionArray = _frameArray.at((int)kKeyframeMove);
                 cActionArray->pushBack(actionFrame);
             }else if(key == "scalex"){
                 scaleX = valueToFloat(value);
             }else if(key == "scaley"){
                 scaleY = valueToFloat(value);
                 ActionScaleFrame* actionFrame = new (std::nothrow) ActionScaleFrame();
                 actionFrame->autorelease();
                 actionFrame->setEasingType(frameTweenType);
                 actionFrame->setEasingParameter(frameTweenParameter);
                 actionFrame->setFrameIndex(frameIndex);
                 actionFrame->setScaleX(scaleX);
                 actionFrame->setScaleY(scaleY);
                 auto cActionArray = _frameArray.at((int)kKeyframeScale);
                 cActionArray->pushBack(actionFrame);
             }else if (key == "rotation"){
                 rotation = valueToFloat(value);
                 ActionRotationFrame* actionFrame = new (std::nothrow) ActionRotationFrame();
                 actionFrame->autorelease();
                 actionFrame->setEasingType(frameTweenType);
                 actionFrame->setEasingParameter(frameTweenParameter);
                 actionFrame->setFrameIndex(frameIndex);
                 actionFrame->setRotation(rotation);
                 auto cActionArray = _frameArray.at((int)kKeyframeRotate);
                 cActionArray->pushBack(actionFrame);
             }else if (key == "opacity"){
                 opacity = valueToInt(value);
                 ActionFadeFrame* actionFrame = new (std::nothrow) ActionFadeFrame();
                 actionFrame->autorelease();
                 actionFrame->setEasingType(frameTweenType);
                 actionFrame->setEasingParameter(frameTweenParameter);
                 actionFrame->setFrameIndex(frameIndex);
                 actionFrame->setOpacity(opacity);
                 auto cActionArray = _frameArray.at((int)kKeyframeFade);
                 cActionArray->pushBack(actionFrame);
             }else if (key == "colorb"){
                 colorB = valueToInt(value);
             }else if(key == "colorg"){
                 colorG = valueToInt(value);
             }else if(key == "colorr"){
                 colorR = valueToInt(value);
                 
                 ActionTintFrame* actionFrame = new (std::nothrow) ActionTintFrame();
                 actionFrame->autorelease();
                 actionFrame->setEasingType(frameTweenType);
                 actionFrame->setEasingParameter(frameTweenParameter);
                 actionFrame->setFrameIndex(frameIndex);
                 actionFrame->setColor(Color3B(colorR,colorG,colorB));
                 auto cActionArray = _frameArray.at((int)kKeyframeTint);
                 cActionArray->pushBack(actionFrame);
             }
             
             
         }
         
     }
     initActionNodeFromRoot(root);
 }