Lite2D UI编辑器1 解析字符串属性

负责解析字符串属性 然后输出对应的Node* 

数据协议可以用json

也可以用高性能的Google FlatBuffers

 
Node * FactoryCreater(string type,  string style )
{
	Node * ret = nullptr;

	if (type == "sprite")
	{
		auto ret = Sprite::create("shouzhi_dianji0.png");

		//解析器
		std::unordered_map<string,string> _map_arrt;

		static string NON = "";

		int cursor = 0;
		int las1 = 0, las2 = 0;
		style.append(",");
		for (int i = 0; i < style.size(); i++)
		{
			if (style[i] == ':')
			{
				las1 = i;
			}
			if (style[i] == ',')
			{
				las2 = i;
				string key =  style.substr(cursor, las1 - cursor);
				string value= style.substr(las1 + 1, las2 - las1 - 1);
				_map_arrt.insert(std::make_pair(key, value));
				cursor = las2 + 1;
			}

		}

		//解析完毕,初始化属性
		float x = atof(_map_arrt["x"].c_str());
		float y = atof(_map_arrt["y"].c_str());
		ret->setPosition(x,y);
		float scale = 1.0f;
		if (_map_arrt["scale"] != NON)
		{
			scale = atof(_map_arrt["scale"].c_str());
		}

		 
		ret->setScale(scale);

		return ret;
	}


	if (type == "label")
	{

	}

	return nullptr;
}




// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
	this->addChild(FactoryCreater("sprite" , "x:100,y:200,scale:0.1"));
	this->addChild(FactoryCreater("sprite", "x:200,y:10"));



    return true;
}

 

转载于:https://my.oschina.net/kkkkkkkkkkkkk/blog/734679

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值