mirror of https://github.com/axmolengine/axmol.git
fix button pressAction scale issue
This commit is contained in:
parent
08d392dd5f
commit
d58426db99
|
@ -395,19 +395,21 @@ void Button::onPressStateChangedToNormal()
|
||||||
_buttonNormalRenderer->stopAllActions();
|
_buttonNormalRenderer->stopAllActions();
|
||||||
_buttonClickedRenderer->stopAllActions();
|
_buttonClickedRenderer->stopAllActions();
|
||||||
|
|
||||||
Action *zoomAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, _normalTextureScaleXInSize, _normalTextureScaleYInSize);
|
// Action *zoomAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, _normalTextureScaleXInSize, _normalTextureScaleYInSize);
|
||||||
_buttonNormalRenderer->runAction(zoomAction);
|
//fixme: the zoomAction will run in the next frame which will cause the _buttonNormalRenderer to a wrong scale
|
||||||
|
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
|
||||||
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
|
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
|
||||||
|
|
||||||
_titleRenderer->stopAllActions();
|
_titleRenderer->stopAllActions();
|
||||||
if (_unifySize)
|
if (_unifySize)
|
||||||
{
|
{
|
||||||
Action *zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1, 1);
|
Action *zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1.0f, 1.0f);
|
||||||
_titleRenderer->runAction(zoomTitleAction);
|
_titleRenderer->runAction(zoomTitleAction);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_titleRenderer->runAction(zoomAction->clone());
|
_titleRenderer->setScaleX(1.0f);
|
||||||
|
_titleRenderer->setScaleY(1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -417,16 +419,10 @@ void Button::onPressStateChangedToNormal()
|
||||||
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
|
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
|
||||||
|
|
||||||
_titleRenderer->stopAllActions();
|
_titleRenderer->stopAllActions();
|
||||||
if (_unifySize)
|
|
||||||
{
|
_titleRenderer->setScaleX(1.0f);
|
||||||
_titleRenderer->setScaleX(1.0f);
|
_titleRenderer->setScaleY(1.0f);
|
||||||
_titleRenderer->setScaleY(1.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_titleRenderer->setScaleX(_normalTextureScaleXInSize);
|
|
||||||
_titleRenderer->setScaleY(_normalTextureScaleYInSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,14 +449,14 @@ void Button::onPressStateChangedToPressed()
|
||||||
_buttonNormalRenderer->setScale(_pressedTextureScaleXInSize + _zoomScale, _pressedTextureScaleYInSize + _zoomScale);
|
_buttonNormalRenderer->setScale(_pressedTextureScaleXInSize + _zoomScale, _pressedTextureScaleYInSize + _zoomScale);
|
||||||
|
|
||||||
_titleRenderer->stopAllActions();
|
_titleRenderer->stopAllActions();
|
||||||
|
Action *zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1.0f + _zoomScale, 1.0f + _zoomScale);
|
||||||
if (_unifySize)
|
if (_unifySize)
|
||||||
{
|
{
|
||||||
Action *zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1 + _zoomScale, 1 + _zoomScale);
|
|
||||||
_titleRenderer->runAction(zoomTitleAction);
|
_titleRenderer->runAction(zoomTitleAction);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_titleRenderer->runAction(zoomAction->clone());
|
_titleRenderer->runAction(zoomTitleAction->clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,16 +470,9 @@ void Button::onPressStateChangedToPressed()
|
||||||
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize +_zoomScale, _normalTextureScaleYInSize + _zoomScale);
|
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize +_zoomScale, _normalTextureScaleYInSize + _zoomScale);
|
||||||
|
|
||||||
_titleRenderer->stopAllActions();
|
_titleRenderer->stopAllActions();
|
||||||
if (_unifySize)
|
|
||||||
{
|
_titleRenderer->setScaleX(1.0f + _zoomScale);
|
||||||
_titleRenderer->setScaleX(1.0f + _zoomScale);
|
_titleRenderer->setScaleY(1.0f + _zoomScale);
|
||||||
_titleRenderer->setScaleY(1.0f + _zoomScale);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_titleRenderer->setScaleX(_normalTextureScaleXInSize + _zoomScale);
|
|
||||||
_titleRenderer->setScaleY(_normalTextureScaleYInSize + _zoomScale);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,17 +216,27 @@ bool UIButtonTest_Scale9_State_Change::init()
|
||||||
_uiLayer->addChild(alert);
|
_uiLayer->addChild(alert);
|
||||||
|
|
||||||
// Create the button
|
// Create the button
|
||||||
Button* button = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
Button* button = Button::create("cocosui/button.png");
|
||||||
// open scale9 render
|
// open scale9 render
|
||||||
button->ignoreContentAdaptWithSize(false);
|
button->ignoreContentAdaptWithSize(false);
|
||||||
button->setScale9Enabled(true);
|
button->setScale9Enabled(true);
|
||||||
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
button->setPosition(Vec2(widgetSize.width / 2.0f - 100, widgetSize.height / 2.0f));
|
||||||
button->setContentSize(Size(200, 60));
|
button->setContentSize(Size(180, 60));
|
||||||
button->setCapInsets(Rect(30,10,40,20));
|
button->setTitleText("Hello Scale9");
|
||||||
button->setPressedActionEnabled(false);
|
button->setPressedActionEnabled(false);
|
||||||
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9_State_Change::touchEvent, this));
|
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9_State_Change::touchEvent, this));
|
||||||
_uiLayer->addChild(button);
|
_uiLayer->addChild(button);
|
||||||
|
|
||||||
|
Button* button2 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
||||||
|
// open scale9 render
|
||||||
|
button2->ignoreContentAdaptWithSize(false);
|
||||||
|
button2->setScale9Enabled(true);
|
||||||
|
button2->setTitleText("Hello scale9");
|
||||||
|
button2->setPosition(Vec2(widgetSize.width / 2.0f + 100, widgetSize.height / 2.0f));
|
||||||
|
button2->setContentSize(Size(180, 60));
|
||||||
|
button2->setPressedActionEnabled(true);
|
||||||
|
button2->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9_State_Change::touchEvent, this));
|
||||||
|
_uiLayer->addChild(button2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue