3.0beta版本
TMXTiledMap 这个类。现在加载地图数据。地图属性值读取错误,一直为空,
是地图属性。不是层或是对像属性
找到原因了
TMXMapInfo这个类获取属性列表的时候返回的不是引用。并且还是const类型,不可操作
插入不了数据
这算不是算是BUG呢
额,getProperties,的时候,返回 const类型,是正常的吧。
下面是有setProperties的。
inline ValueMap getProperties() const { return _properties; };
inline void setProperties(ValueMap properties) {
_properties = properties;
};
////
你可以有这么一个temp的变量,使用读取来的数据。然后,修改值,再set进去。
一般是这么一个流程。
:15: :15: 小白来学习!!
在.h文件有如下定义:
cocos2d::CCPoint _properties;
void setP(cocos2d::CCPoint p){_properties = p;};
cocos2d::CCPoint getP() const { return _properties; };
在.cpp文件这样使用:
setP(ccp(13, 5));
CCPoint _p = getP();
CCLOG("-P: %f, %f", _p.x, _p.y);
_p.x = 135;
CCLOG("-P: %f, %f", _p.x, _p.y);
_p的值是可以改的。
请注意const的位置,它在不同的位置,所起到的作用是不一样的。
你要是换成容器就会出错了,
额,难道有什么不同吗?
我用下面代码同样有测试:
.h
typedef std::map<int, std::string> MAP_1;
typedef MAP_1::value_type vt;
MAP_1 _properties;
void setP(int idx, std::string key){_properties.insert( vt(idx, key) );};
MAP_1 getP() const { return _properties; };
.cpp
setP(13, “str_13”);
MAP_1 _p = getP();
CCLOG("-P: %s.", _p.c_str());
_p.insert(vt(14, “str_14”));
CCLOG("-P: %s", _p.c_str());
log:
Cocos2d: -P: str_13.
Cocos2d: -P: str_14
这样的结果,好像没什么不对吧?
insert完全没有问题。
#include
#include
using namespace std;
typedef map<string, int> StrMap;
class Test
{
public:
Test(){}
~Test(){}
StrMap getMap() const { return _map; }
private:
StrMap _map;
};
int main()
{
Test test;
test.getMap().insert(make_pair("a",1));
test.getMap().insert(make_pair("b",2));
StrMap m = test.getMap();
printf("%s", m.size());
return 0;
}
本来不再回贴.正好我公司有个人也范这样的错.还是干脆发出来.
hi:
你是对的。
这样就插入不了数据了。
应该是返回引用,去掉const,就可以。
这个在下面的版本已经会修改,并很快传到github上。(ps:已经传到git了,https://github.com/cocos2d/cocos2d-x/pull/5210)
你也可以在项目里面先行改下。
(ps:非常感谢!)
(另:可以到官网发issue或者修改之后提交到github)
