Update extensions/GUI/CCControlExtension/CCControlSwitch.cpp

implement setOn(isOn,false)
This commit is contained in:
xyhl515 2013-01-31 22:12:37 +08:00
parent 9b5d0bd251
commit 3316f8c961
1 changed files with 16 additions and 11 deletions

View File

@ -345,17 +345,22 @@ void CCControlSwitch::setOn(bool isOn)
void CCControlSwitch::setOn(bool isOn, bool animated)
{
m_bOn = isOn;
m_pSwitchSprite->runAction
(
CCActionTween::create
(
0.2f,
"sliderXPosition",
m_pSwitchSprite->getSliderXPosition(),
(m_bOn) ? m_pSwitchSprite->getOnPosition() : m_pSwitchSprite->getOffPosition()
)
);
if (animated) {
m_pSwitchSprite->runAction
(
CCActionTween::create
(
0.2f,
"sliderXPosition",
m_pSwitchSprite->getSliderXPosition(),
(m_bOn) ? m_pSwitchSprite->getOnPosition() : m_pSwitchSprite->getOffPosition()
)
);
}
else {
m_pSwitchSprite->setSliderXPosition((m_bOn) ? m_pSwitchSprite->getOnPosition() : m_pSwitchSprite->getOffPosition());
}
sendActionsForControlEvents(CCControlEventValueChanged);
}