看着教程在tiled地图上加了一层collide层,然后通过查找字符串来实现障碍物无法移动。。
但是调试过程发现会报错,查找的property是空的。。。。
希望各位大佬能帮我看看 TAT
void SummonerRift1Scene::onMouseDown(Event*event) {
EventMouse e = (EventMouse)event;
EventMouse::MouseButton mousebutton = e->getMouseButton();
if (mousebutton == EventMouse::MouseButton::BUTTON_RIGHT) {
Vec2 temp1 = Vec2(e->getCursorX(), e->getCursorY());
Vec2 temp = this->convertToNodeSpace(temp1);
Vec2 tileCoord = tileCoordForPosition(temp);//转换为tiled中的坐标,调试时该函数正确
auto _collidable = _tileMap->getLayer("collidable");
int tileGid;
tileGid = _collidable->getTileGIDAt(tileCoord);
if (tileGid) {
Value properties = _tileMap->getPropertiesForGID(tileGid);
auto map = properties.asValueMap();
std::string value = map.at(“collidable”).asString();
if (value.compare(“true”) == 0) {
return;
}
}
if (_player->getPosition().x > temp.x) {
if (_player->isFlippedX() == true)
_player->setFlippedX(false);
}
else {
if (_player->isFlippedX() == false)
_player->setFlippedX(true);
}
if (_player->getNumberOfRunningActions() == 0) {
this->playerMover(temp);
}
else
{
//如果精灵正在运行动作,先停止精灵动作和层动作,再执行移动动作
_player->stopAllActions();
this->stopAllActions();
this->playerMover(temp);
}
}
}


