Cocos2d-x 3.0数据结构——cocos2d::Value
你可以将上面提及的基本类放进 内存管理注意:cocos2d::Value不能像其它cocos2d类型一样使用retain/release和引用计数内存管理 示例Value val; // call the default constructor
if (val.isNull()) {
log("val is null");
}else{
std::string str =val.getDescription();
log("The description of val0:%s",str.c_str());
}
//----------------------------------------------------
Value val1(65); // initialize with a integer
//Value val1(3.4f); // initialize with a float value
//Value val1(3.5); // initialize with a double value
log("The description of the integer value:%s",val1.getDescription().c_str());
log("val1.asByte() = %c",val1.asByte());
//----------------------------------------------------
std::string strV = "string";
Value val2(strV); // initialize with string
log("The description of the string value:%s",val2.getDescription().c_str());
//----------------------------------------------------
auto sp0 = Sprite::create();
Vector<Object*>* vecV = new Vector<Object*>();
vecV->pushBack(sp0);
Value val3(vecV); // initialize with Vector
log("The description of the Vector value:%s",val3.getDescription().c_str());
delete vecV;
//----------------------------------------------------
Map<std::string,Object*>* mapV = new Map<std::string,Object*>();
mapV->insert(strV,sp0);
Value val4(mapV); // initialize with Map
log("The description of the Map value:%s",val4.getDescription().c_str());
delete mapV;
//----------------------------------------------------
Value val6(&val4); // initialize with Map
log("The description of the Value-type value:%s",val6.getDescription().c_str());
//----------------------------------------------------
val2 = val1; // assigning between 2 Value-type
log("operator-> The description of val2:%s",val2.getDescription().c_str());
val2 = 4; //assigning directly
log("operator-> The description of val4:%s",val2.getDescription().c_str());
结果是:
cocos2d: val1.asByte() = A cocos2d: The description of the Vector value: cocos2d: The description of the Map value: cocos2d: The description of the Value-type value: cocos2d: operator-> The description of val2: cocos2d: operator-> The description of val4: 最佳用法
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |