diff --git a/native/cocos/2d/CCTMXLayer.cpp b/native/cocos/2d/CCTMXLayer.cpp index 83b44d9b83..5bf56efb68 100644 --- a/native/cocos/2d/CCTMXLayer.cpp +++ b/native/cocos/2d/CCTMXLayer.cpp @@ -204,6 +204,18 @@ void TMXLayer::setupTiles() } } +void TMXLayer::setTileOpacity(unsigned char opacity) { + _opacity = opacity; + for (int i = 0; i < _layerSize.width; i++) { + for (int j = 0; j < _layerSize.height; j++) { + Sprite* theTile = getTileAt(Vec2(i, j)); + if (theTile) { + theTile->setOpacity(_opacity); + } + } + } +} + // TMXLayer - Properties Value TMXLayer::getProperty(const std::string& propertyName) const { diff --git a/native/cocos/2d/CCTMXLayer.h b/native/cocos/2d/CCTMXLayer.h index 54fd28b91e..12ff2a4242 100644 --- a/native/cocos/2d/CCTMXLayer.h +++ b/native/cocos/2d/CCTMXLayer.h @@ -278,6 +278,13 @@ public: inline void setProperties(const ValueMap& properties) { _properties = properties; }; + + /** + * Set the opacity of all tiles + * @param opacity The new opacity value + */ + void setTileOpacity(unsigned char opacity); + // // Override //