Example #1
0
NS_CC_BEGIN
void TFFrameInfo::getFrames(std::vector<CCSpriteFrame*> &frames)
{
	frames.clear();
	for ( std::vector<std::string>::iterator iter = pngs.begin(); iter != pngs.end();++iter)
	{
		std::string &pngName = *iter;
		CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(pngName.c_str());
		
		CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture,CCRectMake(0,0,texture->getContentSize().width,texture->getContentSize().height));
		if (frame)
		{
			frames.push_back(frame);
			frame->retain();
			frame->setOffset(ccp(0,0));
		}
	}
}
Example #2
0
/**
int frameType; //帧类型
	int actionType; // 行为类型
	int actionId; // 行为id
	int needTime; // 帧播完的时间
	int direction; // 方向
	int framesId; // 帧号
	int conbineType; // 下一个串接类型
*/
void TFActionManager::takeNode(script::tixmlCodeNode *node)
{
	if (!node) return;
	int index = 0;
	_actions.clear();
	if (node->equal("Config") && _actions.empty())
	{
		// 加载行为
		script::tixmlCodeNode actionsNode = node->getFirstChildNode("actions");
		int actionsIndex = 0;
		while (actionsNode.isValid())
		{
			actionsNode.getAttr("id",actionsIndex);
			TFAction action;
			script::tixmlCodeNode actionNode = actionsNode.getFirstChildNode("action");
			while (actionNode.isValid())
			{
				std::map<int,TFActionInfo> frames; // 8个方向的帧
				script::tixmlCodeNode framesNode = actionNode.getFirstChildNode("frames");
				while (framesNode.isValid())
				{
					TFActionInfo actionInfo;
					framesNode.getAttr("dir",actionInfo.direction); // 方向
					framesNode.getAttr("framesid",actionInfo.framesId); // 帧号
					framesNode.getAttr("conbinetype",actionInfo.conbineType); // 合并类型
					framesNode.getAttr("frametype",actionInfo.frameType); // 是否自身播放
					framesNode.getAttr("needtime",actionInfo.needTime); // 所需时间
					if (!actionInfo.needTime) actionInfo.needTime = 1; 
					framesNode.getAttr("actiontype",actionInfo.actionType); // 行为类型
					framesNode.getAttr("distance",actionInfo.distance);
					framesNode.getAttr("angle",actionInfo.angle);
					framesNode.getAttr("offsetx",actionInfo.offset.x);
					framesNode.getAttr("offsety",actionInfo.offset.y);
					framesNode.getAttr("anchorx",actionInfo.anchor.x);
					framesNode.getAttr("anchory",actionInfo.anchor.y);
					frames[actionInfo.direction] = actionInfo;
					framesNode = framesNode.getNextNode("frames");
				}
				action.actions.push_back(frames);
				actionNode = actionNode.getNextNode("action");
			}
			_actions[actionsIndex] = action; //获取到一个行为
			actionsNode = actionsNode.getNextNode("actions");
		}
		// 记载帧数
		script::tixmlCodeNode frameNode = node->getFirstChildNode("frames");
		while (frameNode.isValid())
		{
			std::string type = frameNode.getAttr("type");
			TFFrameInfo frameInfo;
			frameNode.getAttr("id",frameInfo.framesId);
			if (type == std::string("files"))
			{
				script::tixmlCodeNode fileNode = frameNode.getFirstChildNode("file");
				while (fileNode.isValid())
				{
					std::string pngName = fileNode.getAttr("value");
					frameInfo.pngs.push_back(pngName);
					
					CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(pngName.c_str());
				
					CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture,CCRectMake(0,0,texture->getContentSize().width,texture->getContentSize().height));
					if (frame)
					{
						frameInfo.frames.push_back(frame);
					//	frame->retain();
						frame->setOffset(ccp(0,0));
					}
					
					fileNode = fileNode.getNextNode("file");
				}
			}
			if (type == std::string("framecache"))
			{
				
				std::string plistName = frameNode.getAttr("plistname");
				std::string pngName = frameNode.getAttr("pngname");
				CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistName.c_str(), pngName.c_str());
				script::tixmlCodeNode fileNode = frameNode.getFirstChildNode("file");
				while (fileNode.isValid())
				{
					std::string value = fileNode.getAttr("value");
					CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(value.c_str());
					if (frame)
					{
						frameInfo.frames.push_back(frame);
					//	frame->retain();
					}
					
					fileNode = fileNode.getNextNode("file");
				}
				
			}
			if (type == std::string("particlexml"))
			{
				return;
				int numberOfParticles = 0;
				frameNode.getAttr("numberOfParticles",numberOfParticles);
				if (!numberOfParticles) numberOfParticles = 100;
				frameInfo.particle = CCParticleSystemQuad::createWithTotalParticles(numberOfParticles);
				std::string pngname = frameNode.getAttr("pngname");
				CCParticleSystemQuad *particle = frameInfo.particle;
			//	particle->retain();
				
				if( particle)
				{
					loadParticeFromNode(particle,frameNode);
					particle->setTexture( CCTextureCache::sharedTextureCache()->addImage(pngname.c_str() ));
				}
				
			}
			if (type == std::string("particleplist"))
			{
				
			}
			frames[frameInfo.framesId] = frameInfo;
			frameNode = frameNode.getNextNode("frames");

			if (loadCallback)
		    {
				loadCallback->doLoad(0,index++);
			}
		}
		
	}
}