I'm running into an issue with a Tiled map used as a background image for a scrolling scene. I'm using two sprite sheets to provide assets for a background layer. In Tiled, all of these assets appear correctly, but in cocos2d-x, the assets from WorldSelectBG01.png do not appear. Any thoughts on what might be going on here?
Here's what the TMX file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.0.3" orientation="orthogonal" renderorder="right-down" width="1" height="10" tilewidth="640" tileheight="640" nextobjectid="15">
<tileset firstgid="1" name="WorldSelectBG01" tilewidth="640" tileheight="640" tilecount="6" columns="3">
<image source="WorldSelectBG01.png" width="1920" height="1280"/>
</tileset>
<tileset firstgid="7" name="WorldSelectBG02" tilewidth="640" tileheight="640" tilecount="6" columns="3">
<image source="WorldSelectBG02.png" width="1920" height="1280"/>
</tileset>
<layer name="Background" width="1" height="10">
<data encoding="csv">
1,
2,
3,
4,
5,
7,
8,
9,
10,
11
</data>
</layer>
<objectgroup name="GameSelectButtons">
<object id="1" name="gd0" x="394" y="6308"/>
<object id="5" name="gd1" x="251" y="6253"/>
<object id="6" name="gd2" x="140" y="6113"/>
<object id="7" name="gd3" x="227" y="5972"/>
<object id="8" name="gd4" x="362" y="5907"/>
<object id="9" name="gd5" x="499" y="5806"/>
<object id="10" name="gd6" x="458" y="5651"/>
<object id="11" name="gd7" x="336" y="5583"/>
<object id="12" name="gd8" x="241" y="5477"/>
<object id="13" name="gd9" x="294" y="5365"/>
<object id="14" name="gd10" x="322" y="5213"/>
</objectgroup>
</map>
And in cocos2d-x, I'm reading it like this:
void ABTScene::AddBackgroundTileMap(const std::string& backgroundTiledMapFilename)
{
if (backgroundTiledMapFilename.empty())
{
return;
}
const cocos2d::Size visibleSize{ cocos2d::Director::getInstance()->getVisibleSize() };
const cocos2d::Vec2 origin{ cocos2d::Director::getInstance()->getVisibleOrigin() };
_backgroundTiledMap = cocos2d::TMXTiledMap::create(backgroundTiledMapFilename);
CC_ASSERT(_backgroundTiledMap);
if (_backgroundTiledMap)
{
CCLOG("Background tile map read from resource file: %s", _backgroundTiledMap->getResourceFile().c_str());
cocos2d::Vector<cocos2d::TMXObjectGroup*>& objectGroups{ _backgroundTiledMap->getObjectGroups() };
for (const cocos2d::TMXObjectGroup* objectGroup : objectGroups)
{
CCLOG("Object group found in tilemap: %s", objectGroup->getGroupName().c_str());
}
// all tiles are aliased by default, let's set them anti-aliased
for (const auto& child : _backgroundTiledMap->getChildren())
{
static_cast<cocos2d::SpriteBatchNode*>(child)->getTexture()->setAntiAliasTexParameters();
}
_backgroundTiledMap->setAnchorPoint(cocos2d::Vec2(0.0f, 0.0f));
_backgroundTiledMap->setPosition(origin);
const float bgImageScaleFactor = visibleSize.width / _backgroundTiledMap->getContentSize().width;
_backgroundTiledMap->setScale(bgImageScaleFactor);
this->addChild(_backgroundTiledMap, -1);
}
}