mirror of https://github.com/axmolengine/axmol.git
Fixed an issue where ProgressTimer didn't properly set or cascade its opacity (#1830)
This fixes a long standing bug from the Cocos2d-x 3.x days that I fixed in our source code for our games with it. I never made a pull request to Cocos2d-x since they stopped development and maintenance, but thought it might be useful for Axmol!
This commit is contained in:
parent
332eb9afd3
commit
8e37464d67
|
@ -231,8 +231,21 @@ void ProgressTimer::updateDisplayedOpacity(uint8_t parentOpacity)
|
|||
{
|
||||
Node::updateDisplayedOpacity(parentOpacity);
|
||||
|
||||
_sprite->updateDisplayedOpacity(_displayedOpacity);
|
||||
_displayedOpacity = _realOpacity * parentOpacity / 0xFF;
|
||||
|
||||
_sprite->setOpacity(_displayedOpacity);
|
||||
updateColor();
|
||||
updateProgress();
|
||||
|
||||
if (_cascadeOpacityEnabled)
|
||||
{
|
||||
_sprite->updateDisplayedOpacity(_displayedOpacity);
|
||||
|
||||
for(const auto& child : _children)
|
||||
{
|
||||
child->updateDisplayedOpacity(_displayedOpacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressTimer::updateColor()
|
||||
|
@ -242,7 +255,11 @@ void ProgressTimer::updateColor()
|
|||
|
||||
if (!_vertexData.empty())
|
||||
{
|
||||
const auto& sc = _sprite->getQuad().tl.colors;
|
||||
auto sc = _sprite->getQuad().tl.colors;
|
||||
sc.r = sc.r * _sprite->getOpacity() / 255.0f;
|
||||
sc.g = sc.g * _sprite->getOpacity() / 255.0f;
|
||||
sc.b = sc.b * _sprite->getOpacity() / 255.0f;
|
||||
sc.a = sc.a * _sprite->getOpacity() / 255.0f;
|
||||
for (auto& d : _vertexData)
|
||||
{
|
||||
d.colors = sc;
|
||||
|
@ -288,8 +305,12 @@ const Color3B& ProgressTimer::getColor() const
|
|||
|
||||
void ProgressTimer::setOpacity(uint8_t opacity)
|
||||
{
|
||||
_sprite->setOpacity(opacity);
|
||||
_displayedOpacity = _realOpacity = opacity;
|
||||
|
||||
_sprite->setOpacity(_displayedOpacity);
|
||||
updateColor();
|
||||
|
||||
updateCascadeOpacity();
|
||||
}
|
||||
|
||||
uint8_t ProgressTimer::getOpacity() const
|
||||
|
@ -297,6 +318,11 @@ uint8_t ProgressTimer::getOpacity() const
|
|||
return _sprite->getOpacity();
|
||||
}
|
||||
|
||||
uint8_t ProgressTimer::getDisplayedOpacity() const
|
||||
{
|
||||
return _sprite->getDisplayedOpacity();
|
||||
}
|
||||
|
||||
void ProgressTimer::setMidpoint(const Vec2& midPoint)
|
||||
{
|
||||
_midpoint = midPoint.getClampPoint(Vec2::ZERO, Vec2(1, 1));
|
||||
|
@ -596,8 +622,8 @@ Vec2 ProgressTimer::boundaryTexCoord(char index)
|
|||
return Vec2((kProgressTextureCoords >> ((index << 1) + 1)) & 1,
|
||||
(kProgressTextureCoords >> (index << 1)) & 1);
|
||||
}
|
||||
else
|
||||
return Vec2::ZERO;
|
||||
|
||||
return Vec2::ZERO;
|
||||
}
|
||||
|
||||
void ProgressTimer::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
||||
|
|
|
@ -156,6 +156,7 @@ public:
|
|||
virtual const Color3B& getColor() const override;
|
||||
virtual void setOpacity(uint8_t opacity) override;
|
||||
virtual uint8_t getOpacity() const override;
|
||||
virtual uint8_t getDisplayedOpacity() const override;
|
||||
|
||||
/**
|
||||
* @js ctor
|
||||
|
|
Loading…
Reference in New Issue