@fanhaining 写道:
第一、tmx是支持对象层的,cocos2d只是解析
第二、既然你不显示那我自己获取坐标显示,看一眼代码解析的地方只考虑了正地图的坐标转换,45°根本不对
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();// The value for "type" was blank or not a valid class name // Create an instance of TMXObjectInfo to store the object and its properties ValueMap dict; // Parse everything automatically const char* keys[] = {"name", "type", "width", "height", "gid", "id"}; for (const auto& key : keys) { Value value = attributeDict[key]; dict[key] = value; } // But X and Y since they need special treatment // X int x = attributeDict["x"].asInt(); // Y int y = attributeDict["y"].asInt(); Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().y - attributeDict["height"].asInt()); p = CC_POINT_PIXELS_TO_POINTS(p); dict["x"] = Value(p.x); dict["y"] = Value(p.y); int width = attributeDict["width"].asInt(); int height = attributeDict["height"].asInt(); Size s(width, height); s = CC_SIZE_PIXELS_TO_POINTS(s); dict["width"] = Value(s.width); dict["height"] = Value(s.height); // Add the object to the objectGroup objectGroup->getObjects().push_back(Value(dict)); // The parent element is now "object" tmxMapInfo->setParentElement(TMXPropertyObject);
帖子: 1
参与者: 1