experimental::TMXTiledMap nothing changed!

Hello folks ;

I have tried first to load My TMX map normally using TMXTiledMap:: guys !create I discovered that it will stop rendering when it reaches a specific limit I have searched for a solution I some guys on the forum was talking about experimental::TMXTiledMap but it just did the same as normal TMXTiledMap some parts still invisible/unrendered
but I have noticed that GL verts have been reduced also fps dropped from 60 to 30 anyways my question is how can I draw a huge map without any fps drops or invisible parts please help me it’s urgent I can’t advance more in the project with out you guys!

I have tried to do this :

for (int x = 1; x < 499; x++) {
		for (int y = 1; y < 499; y++) {
			Sprite* sprt1 = map->getLayer("earth")->getTileAt(Vec2(x, y));
			Sprite*  sprt2 = map->getLayer("signs")->getTileAt(Vec2(x, y));
			Sprite*  sprt3 = map->getLayer("grass")->getTileAt(Vec2(x, y));
			Sprite* sprt4 = map->getLayer("sea")->getTileAt(Vec2(x, y));
		}
	}

it draws the whole map and fps is still 60 but it everything on the game moves very slowly!

Please help me I might use the experimental::TMXTiledMap wrongly since there isn’t a lot of people are actually talking about it

this is how i load the map

map = experimental::TMXTiledMap::create(str);

How Large are your maps?
In terms of NxM (Like 100 Tiles x 200 Tiles) ?

My map is 500x500

I wish I had more context without getting to into the details of your game, but i’ll ask this:

  • How large is the texture you will be using in your map? (Based on the code snippet you put above, It looks like you may have a large texture that you might want to async load in the background)

  • How are you trying to traverse the map? (depending on how you do it, it may be there reason it’s going slowly

  • Have you changed any of the config setting? (There is a setting in ccConfig.h That look like this #define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 0. You may want to try that and set it to one and see what happens, if saved me with my game using TileMaps

From my experience, If kinda about the optimization part of everything. I would be happy to collaborate with you on this specifically if your open to that kind of stuff :slight_smile:

Thanks for replying:

1-My tilesRes image is 464x2735 (.png) and my tileset is 10x10px
2-I m using the Follow action to follow the player (creating node and then loading the map at the beginning and add it as a child to the node, after all that i do this

auto followTheSprite = Follow::create(GameManager::player->PlayerSprite, 
		GameManager::map->map->getBoundingBox());
	edgeNode->runAction(followTheSprite);

3-I have changed that to 1 to avoid artifacts and weird lines in the map

Note: when I create new layer it draws perfectly seems the limit per layer is 128x128
BUT the tile map uses a LOT of RAM please help me with that too

Can you send me a text image and test map (Something with the same resolution and same tilemap size)

You can send it to mozart.louis.ace@gmail.com

Done i have sent an email

There is a preprocessor flag you can use: CC_FAST_TILEMAP_32_BIT_INDICES

It allows you to create bigger tilemaps, which will probably not work on ancient hardware.

Also, when you do this, make sure you enable the flag on the cocos library as well as your main project, otherwise you can get a lot of issues during linking.

Good day!
(My English is terrible. The text below is a Google translator)
I recently tried using “experemental::TMXTiledMap”.
If I move the Scene, the tiles start to disappear.
see screenshots


Is this an unfinished render or scene “Follow” and “setPostionon” do not work?
My scene move for sprite

My code:

/*Header*/
#if defined (USE_FAST_TMX)
#define TMXMAP cocos2d::experimental::TMXTiledMap
#define TMXLAYER cocos2d::experimental::TMXLayer
#else
#define TMXMAP cocos2d::TMXTiledMap
#define TMXLAYER cocos2d::TMXLayer
#endif

using TileMap_t = TMXMAP;
using TileLayer_t = TMXLAYER;
/*SOURCE*/


bool MapNode::initMap(const std::string & tmx)
{
    m_map = TileMap_t::create(tmx);
    CCASSERT(m_map, "TMX map create failed, m_map is null");

    this->addChild(m_map);
/* ... */
}

/* SCENE */
bool GameScene::init()
{
    this->initMap("0x0.tmx");
    auto sprite = Sprite::create("HelloWorld.png");
    sprite->setScale(Size(16, 16).width / sprite->getContentSize().width);
    this->addNodeToTileMap(sprite);
    auto follow = FollowSmooth::create(sprite, 1.f, 0.2f);
    this->runAction(follow);

}

/*INIT MAP IN SCENE*/
void GameScene::initMap(const std::string & tmx)
{
    if (m_map != nullptr)
    {
        m_map->removeFromParentAndCleanup(true);
    }
    m_map = MapNode::create(this, tmx);
    this->addChild(m_map);
}


Two image

I’m writing new docs for TileMap. Your tilemap looks great. Can I have a copy to use for the example code and screenshots in the docs? PM me if you want.

I can’t send to PM
Error:“Sorry, new users can not upload attachments”

Lol

I noticed that drawing tiles went forward the camera twice as fast.

I did not use the “scale” or “scale factor”

The debugger showed that the “origin” is not correct
I added this line and it all worked. Even if I use Scale.
rect.origin *= 0.5;
Why does this work?

CCFastTMXLayer.cpp

void TMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
{
    updateTotalQuads();

    bool isViewProjectionUpdated = true;
    auto visitingCamera = Camera::getVisitingCamera();
    auto defaultCamera = Camera::getDefaultCamera();
    if (visitingCamera == defaultCamera) {
        isViewProjectionUpdated = visitingCamera->isViewProjectionUpdated();
    }
    
    if( flags != 0 || _dirty || _quadsDirty || isViewProjectionUpdated)
    {
        Size s = Director::getInstance()->getVisibleSize();
          auto rect = Rect(Camera::getVisitingCamera()->getPositionX() - s.width * 0.5f,
                     Camera::getVisitingCamera()->getPositionY() - s.height * 0.5f,
                     s.width,
                     s.height);
        

        Mat4 inv = transform;
        inv.inverse();
        rect = RectApplyTransform(rect, inv);

        //TODO FIXED!
        rect.origin *= 0.5; //<<<<<<<< WHAT?

        rect.size.width, rect.size.height);
        updateTiles(rect);
        updateIndexBuffer();
        updatePrimitives();
        _dirty = false;
    }
  Mat4 inv = transform;
        inv.inverse();
        rect = RectApplyTransform(rect, inv);
1 Like