mirror of https://github.com/axmolengine/axmol.git
Override setOpacity to affect a background sprites
Calling button->setOpacity was affecting only to label. Now opacity value applies also to a background sprites
This commit is contained in:
parent
2b55a76970
commit
b87e932b9f
|
@ -496,6 +496,33 @@ void CCControlButton::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
|
|||
}
|
||||
}
|
||||
|
||||
void CCControlButton::setOpacity(GLubyte opacity)
|
||||
{
|
||||
m_cOpacity = opacity;
|
||||
|
||||
CCObject* child;
|
||||
CCArray* children=getChildren();
|
||||
CCARRAY_FOREACH(children, child)
|
||||
{
|
||||
CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child);
|
||||
if (pNode)
|
||||
{
|
||||
pNode->setOpacity(opacity);
|
||||
}
|
||||
}
|
||||
CCDictElement * item = NULL;
|
||||
CCDICT_FOREACH(m_backgroundSpriteDispatchTable, item)
|
||||
{
|
||||
CCScale9Sprite* sprite = (CCScale9Sprite*)item->getObject();
|
||||
sprite->setOpacity(opacity);
|
||||
}
|
||||
}
|
||||
|
||||
GLubyte CCControlButton::getOpacity()
|
||||
{
|
||||
return m_cOpacity;
|
||||
}
|
||||
|
||||
void CCControlButton::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
|
||||
{
|
||||
m_nState = CCControlStateNormal;
|
||||
|
|
|
@ -70,6 +70,9 @@ protected:
|
|||
//CC_PROPERTY(CCScale9Sprite*, m_backgroundSprite, BackgroundSprite);
|
||||
CCScale9Sprite* m_backgroundSprite;
|
||||
|
||||
/* Override setter to affect a background sprite too */
|
||||
CC_PROPERTY(GLubyte, m_cOpacity, Opacity);
|
||||
|
||||
/** Flag to know if the button is currently pushed. */
|
||||
CC_SYNTHESIZE_READONLY(bool, pushed, IsPushed);
|
||||
// <CCControlState, CCString*>
|
||||
|
@ -105,8 +108,6 @@ public:
|
|||
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
|
||||
virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the title used for a state.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue