diff --git a/cocos/2d/CCTMXXMLParser.cpp b/cocos/2d/CCTMXXMLParser.cpp index 24dcc6fc9e..f07708117a 100644 --- a/cocos/2d/CCTMXXMLParser.cpp +++ b/cocos/2d/CCTMXXMLParser.cpp @@ -340,18 +340,11 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) s.height = attributeDict["height"].asFloat(); layer->_layerSize = s; - layer->_visible = attributeDict["visible"].asBool(); + Value& visibleValue = attributeDict["visible"]; + layer->_visible = visibleValue.isNull() ? true : visibleValue.asBool(); Value& opacityValue = attributeDict["opacity"]; - - if( !opacityValue.isNull() ) - { - layer->_opacity = (unsigned char)(255.0f * opacityValue.asFloat()); - } - else - { - layer->_opacity = 255; - } + layer->_opacity = opacityValue.isNull() ? 255 : (unsigned char)(255.0f * opacityValue.asFloat()); float x = attributeDict["x"].asFloat(); float y = attributeDict["y"].asFloat();