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);