Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17071

UI button Animation Effect

$
0
0

@rmi111 wrote:

Hi,
I want to achieve effects like the following video on cocos UI::Button widget :

Thing is i have manage to achieve close enough,but its not convincing and not behaving properly.My code is below :

void MainMenu::playButtonCallback(Ref* sender, cocos2d::ui::Widget::TouchEventType type)
{	

auto scaleBy = ScaleBy::create(0.7f, 0.7f);
auto ease = EaseElasticInOut::create(scaleBy->clone(), 0.04f);
auto seq1 = Sequence::create(ease, nullptr);

auto scaleBy2 = ScaleBy::create(1.6f, 1.6f);
auto ease2 = EaseElasticOut::create(scaleBy2->clone(), 0.04f);

auto callback = CallFunc::create(this, callfunc_selector(MainMenu::actionFinished));
auto delay = DelayTime::create(0.02);

auto seq2 = Sequence::create(ease2, callback, nullptr);

switch (type)
{
	case ui::Widget::TouchEventType::BEGAN:			

		break;
	case ui::Widget::TouchEventType::ENDED:
		if (!isButtonTouched)
		{
			isButtonTouched = true;

			auto scaleBy = ScaleBy::create(0.7f, 0.7f);
			auto ease = EaseElasticInOut::create(scaleBy->clone(), 0.04f);

			auto scaleBy2 = ScaleBy::create(1.6f, 1.6f);
			auto ease2 = EaseElasticOut::create(scaleBy2->clone(), 0.04f);

			auto callback = CallFunc::create(this,                callfunc_selector(MainMenu::actionFinished));
			auto delay = DelayTime::create(0.02);
			auto seq = Sequence::create(ease, delay, ease2, callback, nullptr);
			playButton->runAction(seq);

		}

		break;
    }
 }

 void MainMenu::actionFinished()
 {
 playButton->setScale(1.0f, 1.0f);
 isButtonTouched = false;
 }

I am not getting proper behaviour and sometimes the button got scaled bigger or smaller if accidentally touched twiced that is the another action occurs in middle of other.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>