Open tankorsmash opened 8 years ago
The behavior is changed in 3.11 but not to the better.
Setting setScrollBarAutoHideEnabled() to false makes the scrollbar invisible as opacity is always 0. setScrollBarOpacity() does not have any effect in this case.
@zilongshanren could you please take a look?
Here is a minimal change to make setScrollBarOpacity() work. It solves the problem temporarily but requires that setScrollBarOpacity() is called after setScrollBarAutoHideEnabled(false).
diff --git a/cocos2d/cocos/ui/UIScrollViewBar.cpp b/cocos2d/cocos/ui/UIScrollViewBar.cpp
index 96c2c74..a5060f3 100644
--- a/cocos2d/cocos/ui/UIScrollViewBar.cpp
+++ b/cocos2d/cocos/ui/UIScrollViewBar.cpp
@@ -164,6 +164,15 @@ void ScrollViewBar::updateLength(float length)
_upperHalfCircle->setPositionY(_body->getPositionY() + length);
}
+void ScrollViewBar::setOpacity(GLubyte opacity)
+{
+ _opacity = opacity;
+ if (!_autoHideEnabled)
+ {
+ ProtectedNode::setOpacity(_opacity);
+ }
+}
+
void ScrollViewBar::onEnter()
{
#if CC_ENABLE_SCRIPT_BINDING
diff --git a/cocos2d/cocos/ui/UIScrollViewBar.h b/cocos2d/cocos/ui/UIScrollViewBar.h
index 4a40e4c..2017545 100644
--- a/cocos2d/cocos/ui/UIScrollViewBar.h
+++ b/cocos2d/cocos/ui/UIScrollViewBar.h
@@ -130,7 +130,7 @@ public:
/**
* @lua NA
*/
- virtual void setOpacity(GLubyte opacity) override { _opacity = opacity; }
+ virtual void setOpacity(GLubyte opacity) override;
virtual GLubyte getOpacity() const override { return _opacity; }
virtual void onEnter() override;
virtual void update(float deltaTime) override;
Cocos2dx 3.10 c++
The following line sets the opacity of the scrollbarview
but it doesn't actually take into effect unless you toggle the autohide:
which calls
It's because the opacity of the ProtectedNode inside the ScrollViewBar is unchanged, because it's not the same as the opacity as ScrollViewBar.
I don't know the solution because I don't yet know why the
setOpacity
call for ScrollView is not doing it already.