[bug?]cocos2d-x 3.2 TMXTiledMap setScale but PhysicsBody not scale

i want to make tilemap scale to screen size, but PhysicsBody is not scale, is cocos2d-x bug(i find tilemap updatePhysicsBodyTransform is not scaled)?
the code:

TMXTiledMap *_map;
std::string filepath_map;
filepath_map = "TileMaps/level_1.tmx";
filepath_map = "TileMaps/level_2.tmx";
_map = TMXTiledMap::create(filepath_map);

TMXObjectGroup *objects = _map->getObjectGroup(“Collision”);

if (objects != nullptr)
{
    float x, y, w, h;
    ValueVector objectsPoint = objects->getObjects();
    for(auto objPointMap : objectsPoint)
    {
        ValueMap objPoint = objPointMap.asValueMap();
        x = objPoint.at("x").asFloat();
        y = objPoint.at("y").asFloat();
        w = objPoint.at("width").asFloat();
        h = objPoint.at("height").asFloat();
        
        Point _point = Point(x + w / 2.0f, y + h / 2.0f);
        Size _size = Size(w, h);
        
        this->makePhysicsObjAt(scene, _point, _size, false, 0, 0.0f, 0.0f, 0, -1);
    }
}

void GameStageLayer_Level_1_0::makePhysicsObjAt(Scene *scene, Point p, Size size, bool d, float r, float f, float dens, float rest, int boxId)
{
auto sprite = Sprite::create();
auto body = PhysicsBody::createBox(size, PHYSICSBODY_MATERIAL_DEFAULT);
body->setTag(boxId);
body->getShape(0)->setRestitution(rest);
body->getShape(0)->setFriction(f);
body->getShape(0)->setDensity(dens);
body->setDynamic(d);
body->setContactTestBitmask(0xFFFFFFFF);
sprite->setPhysicsBody(body);
sprite->setPosition§;
scene->addChild(sprite);
}

g_s = Director::getInstance()->getVisibleSize();
Size s = _map->getContentSize();
_scale_map = g_s.height / s.height;
_map->setScale(_scale_map);

I read that in this version the physics elements doesnt work that way, a possible solution in this case is scale the entire scene

  1. i add all TMXTiledMap to scene, not to layer, but scale not working. how do you fix it?
  2. i don’t use old version. version less than 3.2, have this problem?

Scaling physics objects might be performance heavy for the physics engine, and often you don’t want to do that. In my opinion it’s good idea to keep physics object scale and visual representation scale separated. In your case, you already know what the scale will be (scale_map), you could try applying that scale to your physics objects when you create them at ( this->makePhysicsObjAt(scene, _point, _size, false, 0, 0.0f, 0.0f, 0, -1); )

A better solution would be to have a camera which can zoom in / out.

in version 3.1 I had the same problem, try scene->setScale(desire_scale); that should scale all the physics bodies and the map

thank you KJS, i will try to find and learn new knowledge of “A better solution would be to have a camera which can zoom in / out.”

thank you. i will try your suggestion.
i think the cocos2d-x can fix it.