mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3155 from pktangyue/patch
issue #2406: Override updateDisplayedColor and updateDisplayedOpacity method in Scale9Sprite class. Resolved issue: Color and Opacity of Scale9Sprite will not be changed when it's added to NodeRGBA and run with FadeIn/Out actions.
This commit is contained in:
commit
b11000908e
|
@ -61,8 +61,6 @@ Scale9Sprite::Scale9Sprite()
|
|||
, _bottom(NULL)
|
||||
, _bottomRight(NULL)
|
||||
, _opacityModifyRGB(false)
|
||||
, _opacity(255)
|
||||
, _color(Color3B::WHITE)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -774,8 +772,7 @@ void Scale9Sprite::visit()
|
|||
|
||||
void Scale9Sprite::setColor(const Color3B& color)
|
||||
{
|
||||
_color = color;
|
||||
|
||||
NodeRGBA::setColor(color);
|
||||
Object* child;
|
||||
Array* children = _scale9Image->getChildren();
|
||||
CCARRAY_FOREACH(children, child)
|
||||
|
@ -790,13 +787,12 @@ void Scale9Sprite::setColor(const Color3B& color)
|
|||
|
||||
const Color3B& Scale9Sprite::getColor() const
|
||||
{
|
||||
return _color;
|
||||
return _realColor;
|
||||
}
|
||||
|
||||
void Scale9Sprite::setOpacity(GLubyte opacity)
|
||||
{
|
||||
_opacity = opacity;
|
||||
|
||||
NodeRGBA::setOpacity(opacity);
|
||||
Object* child;
|
||||
Array* children = _scale9Image->getChildren();
|
||||
CCARRAY_FOREACH(children, child)
|
||||
|
@ -811,7 +807,37 @@ void Scale9Sprite::setOpacity(GLubyte opacity)
|
|||
|
||||
GLubyte Scale9Sprite::getOpacity() const
|
||||
{
|
||||
return _opacity;
|
||||
return _realOpacity;
|
||||
}
|
||||
|
||||
void Scale9Sprite::updateDisplayedColor(const cocos2d::Color3B &parentColor)
|
||||
{
|
||||
NodeRGBA::updateDisplayedColor(parentColor);
|
||||
Object* child;
|
||||
Array* children = _scale9Image->getChildren();
|
||||
CCARRAY_FOREACH(children, child)
|
||||
{
|
||||
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (pNode)
|
||||
{
|
||||
pNode->updateDisplayedColor(parentColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Scale9Sprite::updateDisplayedOpacity(GLubyte parentOpacity)
|
||||
{
|
||||
NodeRGBA::updateDisplayedOpacity(parentOpacity);
|
||||
Object* child;
|
||||
Array* children = _scale9Image->getChildren();
|
||||
CCARRAY_FOREACH(children, child)
|
||||
{
|
||||
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (pNode)
|
||||
{
|
||||
pNode->updateDisplayedOpacity(parentOpacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -97,8 +97,6 @@ protected:
|
|||
Sprite* _bottomRight;
|
||||
|
||||
bool _opacityModifyRGB;
|
||||
GLubyte _opacity;
|
||||
Color3B _color;
|
||||
|
||||
void updateCapInset();
|
||||
void updatePositions();
|
||||
|
@ -312,6 +310,9 @@ public:
|
|||
virtual GLubyte getOpacity() const;
|
||||
virtual void setColor(const Color3B& color);
|
||||
virtual const Color3B& getColor() const;
|
||||
|
||||
virtual void updateDisplayedOpacity(GLubyte parentOpacity);
|
||||
virtual void updateDisplayedColor(const Color3B& parentColor);
|
||||
|
||||
virtual bool updateWithBatchNode(SpriteBatchNode* batchnode, Rect rect, bool rotated, Rect capInsets);
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ static std::function<Layer*()> createFunctions[] = {
|
|||
CL(S9FrameNameSpriteSheetRotatedInsets),
|
||||
CL(S9_TexturePacker),
|
||||
CL(S9FrameNameSpriteSheetRotatedInsetsScaled),
|
||||
CL(S9FrameNameSpriteSheetRotatedSetCapInsetLater)
|
||||
CL(S9FrameNameSpriteSheetRotatedSetCapInsetLater),
|
||||
CL(S9CascadeOpacityAndColor)
|
||||
};
|
||||
|
||||
static int sceneIdx=-1;
|
||||
|
@ -641,3 +642,49 @@ std::string S9FrameNameSpriteSheetRotatedSetCapInsetLater::subtitle()
|
|||
{
|
||||
return "createWithSpriteFrameName(); setInsetLeft(32); setInsetRight(32);";
|
||||
}
|
||||
|
||||
//
|
||||
//// S9CascadeOpacityAndColor
|
||||
//
|
||||
|
||||
void S9CascadeOpacityAndColor::onEnter()
|
||||
{
|
||||
S9SpriteTestDemo::onEnter();
|
||||
Size winSize = Director::getInstance()->getWinSize();
|
||||
float x = winSize.width / 2;
|
||||
float y = 0 + (winSize.height / 2);
|
||||
LayerRGBA* rgba = LayerRGBA::create();
|
||||
rgba->setCascadeColorEnabled(true);
|
||||
rgba->setCascadeOpacityEnabled(true);
|
||||
this->addChild(rgba);
|
||||
|
||||
CCLog("S9CascadeOpacityAndColor ...");
|
||||
|
||||
auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png");
|
||||
CCLog("... created");
|
||||
|
||||
blocks_scaled_with_insets->setPosition(Point(x, y));
|
||||
CCLog("... setPosition");
|
||||
|
||||
rgba->addChild(blocks_scaled_with_insets);
|
||||
Sequence* actions = Sequence::create(FadeIn::create(1),
|
||||
TintTo::create(1, 0, 255, 0),
|
||||
TintTo::create(1, 255, 255, 255),
|
||||
FadeOut::create(1),
|
||||
NULL);
|
||||
RepeatForever* repeat = RepeatForever::create(actions);
|
||||
rgba->runAction(repeat);
|
||||
CCLog("this->addChild");
|
||||
|
||||
CCLog("... S9CascadeOpacityAndColor done.");
|
||||
}
|
||||
|
||||
std::string S9CascadeOpacityAndColor::title()
|
||||
{
|
||||
return "Scale9Sprite and a LayerRGBA parent with setCascadeOpacityEnable(true) and setCascadeColorEnable(true)";
|
||||
}
|
||||
|
||||
std::string S9CascadeOpacityAndColor::subtitle()
|
||||
{
|
||||
return "when parent change color/opacity, Scale9Sprite should also change";
|
||||
}
|
||||
|
|
|
@ -188,3 +188,14 @@ public:
|
|||
virtual std::string title();
|
||||
virtual std::string subtitle();
|
||||
};
|
||||
|
||||
// S9CascadeOpacityAndColor
|
||||
|
||||
class S9CascadeOpacityAndColor : public S9SpriteTestDemo
|
||||
{
|
||||
public:
|
||||
virtual void onEnter();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string subtitle();
|
||||
};
|
Loading…
Reference in New Issue