这地方为啥这么麻烦啊,我看下面的函数只是接受一个const char*的参数啊
【修改前】
auto str = String::createWithContentsOfFile (FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
【修改后】
auto str = String::createWithContentsOfFile(file.c_str());
难道还有什么特殊的意义吗?
这地方为啥这么麻烦啊,我看下面的函数只是接受一个const char*的参数啊
【修改前】
auto str = String::createWithContentsOfFile (FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
【修改后】
auto str = String::createWithContentsOfFile(file.c_str());
难道还有什么特殊的意义吗?
这是他们的源代码:
TMXTiledMap * TMXTiledMap::create(const std::string& tmxFile)
{
TMXTiledMap *ret = new TMXTiledMap();
if (ret->initWithTMXFile(tmxFile))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std::string& resourcePath)
{
TMXTiledMap *ret = new TMXTiledMap();
if (ret->initWithXML(tmxString, resourcePath))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
实际上时差不多的,直接使用create就可以

为嘛我在加入
std::string file = “1.tmx”;
auto str = String::createWithContentsOfFile (FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
_tileMap = TMXTiledMap::createWithXML(str->getCString(),"");
_background = _tileMap->layerNamed(“Background”);
addChild(_tileMap, -1);
这段代码后就蹦了呢?
// private
TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
TMXLayer *layer = TMXLayer::create(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->_ownTiles = false;
layer->setupTiles();
return layer;
}
这个地方 TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo); 就返回null了
@楼主
请问可以把Tileset的图片用TexturePacker打包来弄吗?
跟了下代码,出错处:
// If all the tiles are 0, return empty tileset
CCLOG(“cocos2d: Warning: TMX Layer ‘%s’ has no tiles”, layerInfo->_name.c_str());
都是按步骤来的 使用editor有什么问题?
没有创建层?
创建了 Background
我貌似找到原因了。。。
因为添加的层中没有使用到图块中的图,所以
if( gid != 0 )
{
// Optimization: quick return
// if the layer is invalid (more than 1 tileset per layer) an CCAssert will be thrown later
if( (gid & kTMXFlippedMask) >= tileset->_firstGid )
return tileset;
}
中的gid一直为0,就出现了46楼中的问题。。
估计还是使用title map的问题,加载title map自带的例子没问题
自己弄的有问题,但是是按照教程来的,为嘛不行呢?
嗯 确实是 后来加图块,就可以了,主要还是不会使用。
是因为没把图片文件一起放在Resource里面么?(帖子回帖量多了,系统就不自动提醒要自己手动查看,所以之前一致没看到提问。)
这教程里用的素材都没有使用TexturePacker。第一帖里的素材包,就有全部素材了
我出现了和你一样的问题,是如何解决的呢?
我把资源放到一个文件夹了,resource,但是挂掉了
_tileMap = TMXTiledMap::createWithXML(str->getCString(),"");挂在这
楼主,请教了
如果你确定代码没问题的话,你能上传一下你自制的地图文件么?不然就一起传来。我估计是地图编辑器制作地图的时候有哪里不规范。
一开始也出现了前面几楼出现的问题,后来发现是没有对地图进行任何绘制就保存了的原因,楼主是否能在部分1里的内容加上绘制的过程,以免其他像我一样的小白在这个问题是浪费过多的时间。
楼主这里的_mode怎么定义的啊?谢谢
厉害,学习下。